Order of killing parent and child processes

killprocess

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!

Best Answer

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.