Linux – What’s the best way to send a signal to all members of a process group


I want to kill a whole process tree. What is the best way to do this using any common scripting languages? I am looking for a simple solution.

Best Solution

You don't say if the tree you want to kill is a single process group. (This is often the case if the tree is the result of forking from a server start or a shell command line.) You can discover process groups using GNU ps as follows:

 ps x -o  "%p %r %y %x %c "

If it is a process group you want to kill, just use the kill(1) command but instead of giving it a process number, give it the negation of the group number. For example to kill every process in group 5112, use kill -TERM -- -5112.