Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

2 Answers

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
add comment

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

kill -15 -12345

or

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
1  
"--" 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
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.