tags:

views:

315

answers:

4

When you invoke "kill" on a parent process, are the child processes subsequently killed as well?

A: 

Yes, it will; use kill -1 : http://unixhelp.ed.ac.uk/shell/jobz5.html

meagar
+4  A: 

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.

profjim
Despite the "yes" and "no", my answer and meager's are not inconsistent.
profjim
I find your answer more complete. You can always trap signals and do funky stuff. So, it is safe not to assume anything when it comes to killing child processes by killing the parent.
hackworks
+1  A: 

man 2 kill

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.

ephemient
A: 

No




DigitalRoss