Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am running a bash script as a background job. The bash script calls a time-consuming executable. If I am not wrong, the running of the bash script is the parent process and the running of the executable is the child process.

I now want to stop the whole running by killing the parent process which is the background job

kill -9 $(jobs -p)

The terminal shows that the running of the bash script is killed. But the running of the executable still hangs on the output of top. I just wonder how to also kill the child process?

Thanks and regards!

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

Use a negative PID which will cause a process group to be killed. The -- tells kill that the rest of the arguments are not option switches so the hyphen (minus) before the PID won't confuse it.

kill -- -12345

Also, -9 is a last resort. Don't use it until you've tried at least -15 (SIGTERM, which is the default) first. This gives a program the chance to do housekeeping before it exits. See When should I use kill -9 or Useless use of kill -9 or kill -9.

share|improve this answer
add comment

killall might give you better results.

Warning: killall behaves differently on the different *nix's. On Linux, it will kill the processes with the titles matching the argument. On Solaris, it will kill EVERY process, not just the ones you specify. So on Solaris, running killall as root will effectively shut down the machine. Make sure you know which behavior the command follows

share|improve this answer
4  
I'd warn, killall behaves differently on the different *nix's. On Linux, it will kill the processes with the titles matching the argument. On Solaris, it will kill EVERY process, not just the ones you specify. So on Solaris, running killall as root will effectively shut down the machine. Make sure you know which behavior the command follows. –  Babu Jan 4 '10 at 19:37
    
Thanks for this comment, @Babu, this is definitely something i overlooked. –  Deniz Zoeteman Jan 4 '10 at 19:41
1  
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.