LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-19-2019, 03:03 AM   #1
doru
Member
 
Registered: Sep 2008
Distribution: Ubuntu 8.04 LTS Server
Posts: 138

Rep: Reputation: 19
bash while ctrl-c inconsistent behaviour


For the first while, ctrl-c breaks the loop, for the second it doesn't, it just stops arecord. Why?

Code:
while true; do sleep 1h; done
while true; do arecord somefile.wav; done

Last edited by doru; 06-19-2019 at 03:30 AM.
 
Old 06-19-2019, 03:59 AM   #2
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,901

Rep: Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025
Most likely arecord is setting up its own signal handler for SIGINT, while sleep doesn't.
 
1 members found this post helpful.
Old 06-19-2019, 07:08 AM   #3
doru
Member
 
Registered: Sep 2008
Distribution: Ubuntu 8.04 LTS Server
Posts: 138

Original Poster
Rep: Reputation: 19
Quote:
Originally Posted by GazL View Post
Most likely arecord is setting up its own signal handler for SIGINT, while sleep doesn't.
sleep alone does exit on ctrl-c, like most programs. You say that the signal is passed to while?!
 
Old 06-19-2019, 02:26 PM   #4
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,901

Rep: Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025
I don't understand the exact mechanics -- possibly it checks the return code from the sleep (code 130 when interrupted by SIGINT) -- but however it works, an interrupted command will also terminate the while loop it is contained in.

My guess is that arecord traps the SIGINT itself, and then exits normally, thus the shell/while-loop doesn't notice that it's been interrupted and starts the next iteration of the loop.
 
1 members found this post helpful.
Old 07-01-2019, 05:23 AM   #5
doru
Member
 
Registered: Sep 2008
Distribution: Ubuntu 8.04 LTS Server
Posts: 138

Original Poster
Rep: Reputation: 19
Code:
$ while true; do echo a; sleep 1; false; done #does not stop at false 
$ cat while.sh #does not stop at myfunc 
myfunc() { echo b; return 130; }
while true; do
  echo a
  myfunc
  echo myfunc returns $?
  sleep 1
  done
They are definitely hiding something from us ...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ctrl+c and ctrl+v and ctrl+a dont work fine after install Nvidia drivers eros1989 Linux - Software 5 03-05-2019 07:00 AM
How to disable Ctrl+C, Ctrl+V, Ctrl+X in rdesktop? Aswathy Linux - Newbie 1 01-19-2011 06:22 PM
Recognizing ctrl+c,ctrl+l,ctrl+d in C programs leonardo6023 Programming 1 08-19-2009 09:23 AM
Inconsistent bitwise operator behaviour in C oneandoneis2 Programming 4 02-08-2007 03:20 AM
Inconsistent behaviour of java.awt in Linux/Windows liangzan Programming 2 09-08-2005 09:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration