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.
kill(-123, SIGTERM)
would send theSIGTERM
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 07 '14 at 22:25