1

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!

Tim
  • 1,487
  • 6
  • 28
  • 43

2 Answers2

3

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.

Christian
  • 4,703
  • 2
  • 24
  • 27
  • Thanks! Is there a script for killing them all? – Tim Jan 05 '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 05 '10 at 17:17
  • 1
    **1.** Zombies are harmless. **2.** This is not how you prevent zombies. Every process you kill will become a zombie until its parent is has collected the exit status. **3.** Whether the order of killing parent and child matters depends on what they are doing. There may be cases where it makes a difference, but the difference isn't zombies. – kasperd Apr 28 '18 at 18:58
3

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

kill -15 -12345

or

kill -- -12345
Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151
  • Is the negative PID the negative of the parent PID? What does "--" mean? – Tim Jan 06 '10 at 02: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 06 '10 at 06:10