1

This question already has an answer here:

Let us say I have process A which spawns process B, which spawns process C. Under what circumstances will killing A kill the whole chain (or tree I guess) and when will it not? I sometimes find it does, and sometimes that B ends up with ppid 1 and C is untouched.

Does this behaviour vary between particular Linux kernel versions?

marked as duplicate by Gilles linux Nov 8 '14 at 0:50

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

5

The kill() system call and the kill shell command can be used to kill either processes or process groups. Either way, there is no "cascading", ever.

  • When the kill() system call or kill shell command is given a positive integer, this represents a process. The signal is sent to that process and no others.

  • When the kill() system call is given a negative integer or the kill shell command is given a job identifier beginning with % (such as %1 or %2), the signal is sent simultaneously to all members of a process group. Process groups are a job control feature. In interactive shell use, each shell pipeline (like sed s/foo/bar/ | cat -n | gzip) is made up of 1 or more processes that are all part of the same process group.

(For the system call there are a few extra cases: -1 sends to every process, 0 sends to yourself).

None of this means that when one process dies another process won't also die because of some other reason. For example:

  • A process that spawns a child may intercept a termination signal and pass it along to the child it created before itself exiting as a means of cleaning up after itself.
  • When an earlier process in a shell pipeline such as the one above dies (for any reason), the later processes in the shell pipeline often promptly terminate as well because they aren't receiving any input anymore.

The kernel isn't responsible at all for such "additional" consequences and they depend on how the software involved behaves.

  • Do you mean that if the pid of A is 123, kill -123 would simultaneously send a kill to A, B and C? – Gaius Nov 7 '14 at 22:18
  • No. kill(-123, SIGTERM) would send the SIGTERM signal to all of the members of process group number 123, which doesn't necessarily have anything to do with the process whose ID is 123. Most commonly there is a relationship though: the process group is typically numbered after the process ID of the process group leader. But A might be a member of some other process group, B and/or C might not be in the same process group as A (it depends how they were spawned), etc... – Celada Nov 7 '14 at 22:25
  • Ah also see unix.stackexchange.com/a/2917/5560 – Gaius Nov 8 '14 at 8:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.