Sometimes, sending a SIGTERM to a process will cause it to send SIGTERM to all its child processes. However, sometimes this doesn't work.

Is there a command or a utility that will allow me to kill a process and all its child processes at the same time? I usually resort to manually collecting all the pids into one kill command, but it feels stupid.

This SO question asks how to do this with perl, but anything that gets the job done would be great.

  • Looks like pkill -9 is more powerful than pkill, for whatever reason.
    – Andrew
    Apr 27, 2019 at 18:46
  • @Andrew - It's not for "whatever reason". It's because 'kill' is not really named correctly. What it does is send a signal to the process. The signal it sends by default is TERM, which by default will terminate the process. But, the process can 'catch' it so it can do cleanup work before it exits. The -9 causes it to send the KILL signal, which terminates the process immediately. You want to avoid doing this if possible. Only use -9 if a regular kill didn't work in the first few seconds. Jan 2 at 20:38

4 Answers 4


This SO question covers this.


Assuming that the processes share a session identifier (which they should unless they've explicitly called setsid(), you can kill them by session using pkill:

user@machine:~> ps -o pid,sess,cmd -U user
12804 12804 -bash
12916 12804 ps -o pid,sess,cmd -U user
user@machine:~> sh
sh-3.00$ sh
sh-3.00$ sh
sh-3.00$ sh
sh-3.00$ sh
sh-3.00$ sh
sh-3.00$ ps -o pid,sess,cmd -U user
12804 12804 -bash
12920 12804 sh
12921 12804 sh
12922 12804 sh
12924 12804 sh
12926 12804 sh
12928 12804 sh
12937 12804 ps -o pid,sess,cmd -U user

If from another terminal I do:

pkill -9 -s 12804

Then everything dies in one fell swoop.

You can similarly kill by process group, though this tends to be more useful for many children that are all one level below a parent, not a chain of associated processes.


Usually, a responding client should receive a sigterm and off itself, thereby terminating all its forked child processes. If, on the other hand, the client is not responding, a normal termination signal will probably evoke no response.

So you then proceed to send a SIGKILL, which tells the system itself to Make That Process Stop, Now - which it can do most of the times, except when the process is in a state of ininterruptible sleep, like waiting for some I/O input or similar.

In that case, even the SIGKILL will end up doing nothing to the process; the child process will probably in a similar state of retardation.

There is a border case where the parent process might terminate just nicely, but the child process is not killable. Then you will end up with a zombie process that cannot be cleaned up since its father is gone, but it is not responding to anything. The only way to get rid of those is a reboot; in most cases, though, they are quite harmless, as the only thing they do is take up a PID while whatever socket they tried to use has withered away already.


If I want to kill the process tree of Firefox, then is it possible to kill it by the above command "pkill -9 -s firefox"

Not the answer you're looking for? Browse other questions tagged .