The bells and bells_copy are scripts which I wrote. some were stopped with Ctrl-Z while others were allowed to run normally.
timeout is a command that is executed from within a function in both scripts and at Ctrl-Z, the timeout command is killed using "killall timeout". Can anyone explain why the exit command refuses to exit the terminal?
I tried killing the processes individually using their <pid>s but ps gives the same report as jobs i.e no change.
How do i go about trashing the terminal successfully with exit?
tnx
Well, first, Ctrl+Z doesn't terminate processes, it suspends them to the background. Also, running the same script numerous times can cause a hiccup, but since we don't know what said scripts do and what their code looks like it's hard to tell.
Assuming bells & bells_copy deal with I/O (i.e.: read/write from/to the hard disk), it could be causing the issue at hand. What command exactly do you run to kill the processes? If you use "kill <pid>" then it won't do much of anything. By default, kill uses the signal 15 which tells the process "hey, when you get done running, or at your earliest convenience, please end". However, if you use signal 9 (kill -9 <pid>), it says "<pid>, I don't care what you're doing, terminate now!"
If you really don't want to investigate this issue, however, just run "killall <process name>" and it'll kill all instances of that process.
I used "killall <processname>" and in the script logic, when the script catches a trap, either STOP, TERMINATE or INTERRUPT, it enters a function where "killall <processname>" is run. maybe i will run a test again and see how the "jobs" and "ps" command will report when the script is allowed to run to completion and when interrupted with Ctrl-Z.
will give you feedback later. tnx
I think the problem lies with the script logic. Can you help me out.
I ran the script and then allowed it to exit normally, without any interrupts. When I checked the "ps" and "jobs" command, I got the expected result.
Then i ran the script and interrupted it. When i ran the "ps" command this is the result:
And when I ran "jobs" this is the report received.
Code:
[1]+ Stopped ./bells2
Ctrl-Z should have killed the timeout process but it didn't.
I am attaching a copy of the script for your perusal.
I think there is a consequence to this report, not only that it stops the terminal with user privileges from exiting. There can be other consequences.
Thanks for your kind attention. I do appreciate your response.
david
1) Ctrl+Z is not an interrupt. It simply moves the process to the background so you can continue working on things while said process continues running.
2) Ctrl+Z does NOT kill a process. Read #1 to understand why.
3) This line looks like it has an error: "timeout "$duration"m top;". First, then '"m' part. Then the "top;".
1) Ctrl+Z is not an interrupt. It simply moves the process to the background so you can continue working on things while said process continues running.
2) Ctrl+Z does NOT kill a process. Read #1 to understand why.
3) This line looks like it has an error: "timeout "$duration"m top;". First, then '"m' part. Then the "top;".
regards #1: thanks for the insight. I thought Ctrl-Z kills processes. that explains my confusion. but Ctrl-z did not kill the process itself. how would you kill a script that is running and is placed on a timer if ctrl-c doesn't kill it?
regards #3: that line has no error. $duration expands to the duration the user inputted and the m is the suffix that gives the duration in minutes as distinct from 's' for seconds and 'h' for hours. as for top, i intended using : command for the commands part of the timeout command (read the man) but bash did not accept :, so i used a command that should last longer than the input $duration.
thanks. again, if ctrl-c doesn't kill a process hung on a timer, what will?
Last edited by emekadavid; 08-06-2012 at 03:37 PM.
regards #1: thanks for the insight. I thought Ctrl-Z kills processes. that explains my confusion. but Ctrl-z did not kill the process itself. how would you kill a script that is running and is placed on a timer if ctrl-c doesn't kill it?
regards #3: that line has no error. $duration expands to the duration the user inputted and the m is the suffix that gives the duration in minutes as distinct from 's' for seconds and 'h' for hours. as for top, i intended using : command for the commands part of the timeout command (read the man) but bash did not accept :, so i used a command that should last longer than the input $duration.
thanks. again, if ctrl-c doesn't kill a process hung on a timer, what will?
It's been a few months since I did work in Bash, heh.
For killing processes, assuming you haven't ran any other commands since running bells.sh, you can do kill -9 $! which expands to "kill -9 <pid of last ran command>". However, I really think you should better debug your code in the fact of taking it apart piece by piece, and seeing where and why it hangs.
It's been a few months since I did work in Bash, heh.
For killing processes, assuming you haven't ran any other commands since running bells.sh, you can do kill -9 $! which expands to "kill -9 <pid of last ran command>". However, I really think you should better debug your code in the fact of taking it apart piece by piece, and seeing where and why it hangs.
i was testing the trap mechanism on the script, i.e ctrl-c, which did not work as plotted. but ctrl-z sent the script execution to the background. i think the code is okay; from the threads so far, just i didn't understand why it didn't catch ctrl-c.
will keep wondering.
ctrl+c sends the SIGINT signal to the process, which then I guess the script forwards the signal to the currently running command in the script. Sending SIGINT is like asking the process to die. However if the process was suspended (ctrl+z, SIGTSTP), or the process was programmed to deal with SIGINT other than the default way (to terminate), the process doesn't die if ctrl+c is given. You can send the SIGQUIT signal usually via ctrl+\ which most of the time when ctrl+c doesn't work, this works.
Bookmarks