pkill
is doing exactly what you told it to do: it killed the processes whose parent is 100. Not processes whose parent's parent is 100.
Neither Linux's pkill
nor FreeBSD's has an option to traverse the process tree. You can call pstree -l
and parse its output.
Keep in mind that if A forks B, B forks C and then B dies, there's no parent-child relation left that can connect A and C.
There may be a way to kill all these processes, but beware that it might overmatch.
If you pass a negative process ID to kill
, that kills the whole process group. This is atomic, so it works even if one of the processes forks just as you're running kill
. This only kills the processes that haven't placed themselves in their own group, and it also kills the parent process and others if they're in the same process group. Run ps -o pgid …
to see the process group ID of processes.
If all the processes you want to kill have a particular file open, you can use fuser -k /some/file
to kill all the processes that have this file open.
Another option on Linux is to run the processes in their own PID namespace. You can then kill the whole namespace with by killing the pseudo-PGID -1 from within the namespace.