When you invoke "kill" on a parent process, are the child processes subsequently killed as well?
No, not automatically.
Commonly, when a parent is killed the child will be sent a HUP signal. At least this is true when the parent is a shell. I'm not sure about if this comes for free whenever a child was fork()ed.
But this can be defeated, for instance if the parent is a shell and the child was started using nohup child&
, or if the child itself declared that it would ignore HUP signals.
int kill(pid_t pid, int sig);
If pid is greater than 0, sig shall be sent to the process whose process ID is equal to pid.
If pid is negative, but not -1, sig shall be sent to all processes (excluding an unspecified set of system processes) whose process group ID is equal to the absolute value of pid, and for which the process has permission to send a signal.
Unless setpgid
or similar function is called, a child process is in the same process group as its parent. For example, jobs started by your shell belong to the same process group as the shell itself.
Thus kill -HUP $$
sends SIGHUP
to your shell, while kill -HUP -$$
sends SIGHUP
to all processes in your current session, including children of your shell.