2
votes
1answer
42 views

Forward SIGTERM to child in Bash

I have a Bash script, which looks similar to this: #!/bin/bash echo "Doing some initial work...."; /bin/start/main/server --nodaemon Now if the bash shell running the script receives a SIGTERM ...
2
votes
1answer
275 views

ctrl c vs. ctrl z with foreground job

Ctrl+Z stops the job whereas Ctrl+C kills the job. Why is that? Wouldn't the other way make more sense? z@z-lap:~$ sleep 100& [1] 4458 z@z-lap:~$ sleep 200& [2] 4459 z@z-lap:~$ jobs [1]- ...
7
votes
1answer
121 views

stderr over ssh -t

This sends output to STDERR, but does not propagate Ctrl+C (i.e. Ctrl+C will kill ssh but not the remote sleep): $ ssh localhost 'sleep 100;echo foo ">&2"' This propagates Ctrl+C (i.e. ...
3
votes
4answers
2k views

Ctrl-C with two simultaneous commands in bash

I want to run two commands simultaneously in bash on a Linux machine. Therefore in my ./execute.sh bash script I put: command 1 & command 2 echo "done" However when I want to stop the bash ...
6
votes
2answers
201 views

Decode Flags for Kill Command

I am new to Shell Scripting. I saw this Command on a Book for Linux shell Scripting $ kill -HUP 1234 >killout.txt 2>killerr.txt I know what the command does, but i am not able to understand ...
4
votes
3answers
221 views

What process is running before I even get a prompt?

When I log in to a specific server I see the following: Note that I get get Last login: ... information but no prompt. I hit Ctrl+C and only then do I get my prompt, thus proving that my username ...
2
votes
2answers
344 views

Why is `kill -s INT <zsh PID>` behaving differently from `Ctrl-C`?

Starting with: % donothing () { echo $$; sleep 1000000 } % donothing 47139 If at this point I hit Ctrl-C at the same terminal that is controlling the shell, then the function donothing does indeed ...
7
votes
1answer
241 views

What should interactive shells do in orphaned process groups?

(Re-posting in unix per the suggestion in http://stackoverflow.com/questions/13718394/what-should-interactive-shells-do-in-orphaned-process-groups) The short question is, what should a shell do if it ...
7
votes
1answer
1k views

“trap … INT TERM EXIT” really necessary?

Many examples for trap use trap ... INT TERM EXIT for cleanup tasks. But is it really necessary to list all the three sigspecs? The manual says: If a SIGNAL_SPEC is EXIT (0) ARG is executed on ...
8
votes
4answers
4k views

How can I kill and wait for background processes to finish in a shell script when I Ctrl+C it?

I'm trying to set up a shell script so that it runs background processes, and when I Ctrlc the shell script, it kills the children, then exits. The best that I've managed to come up with is this. It ...
7
votes
1answer
1k views

confirmed exit using trap

I am trying to trap the Ctrl+C signal asking a confirmation from the user. The trapping part works fine. But once the signal gets trapped, it does not return to the normal execution. Instead, it quits ...
1
vote
1answer
2k views

Can you specify a separate trap in a subshell created with ()?

I'm writing a script that starts a subshell to go off and do some work. In a special case, the script needs to tell the subshell to cleanly stop what it's doing and exit early. However, my ...
31
votes
5answers
5k views

Timing out in a shell script

I have a shell script that's reading from standard input. In rare circumstances, there will be no one ready to provide input, and the script must time out. In case of timeout, the script must execute ...