Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

It seems to me killing either of parent and child processes will not affect the other.

So if want to kill a parent process and all its child processes, I guess I have to kill them one by one. I wonder which way is better: kill the parent first then the child, or kill the child first then the parent.

If there is any way to kill a parent process and all its children and grandchildren in a single line or some script, please let me know.

Thanks and regards!

share|improve this question
up vote 3 down vote accepted

you should first kill the child processes and than the parent processes to prevent zombies. or you can kill them all at once with kill pid1 pid2 ...

if you want to kill a parent with some childs, you can use ps with extended info (or pstree, ...) to get the pid and parent pid (ppid). with these information you can script the killing.

share|improve this answer
Thanks! Is there a script for killing them all? – Tim Jan 5 '10 at 17:10
i do not have one at hand. you could do it with a combination of kill, ps and awk or grep. – Christian Jan 5 '10 at 17:17

You can kill the whole group by using a negative PID.

kill -15 -12345


kill -- -12345
share|improve this answer
Is the negative PID the negative of the parent PID? What does "--" mean? – Tim Jan 6 '10 at 2:18
"--" means use the default signal (15) and don't consider the rest of the arguments as options (necessary since there's a dash as the first character of the PID). Yes, that would be the negative of the parent PID. – Dennis Williamson Jan 6 '10 at 6:10

Your Answer


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.