Re: How to kill child & parent process simulanteously

From: Pascal Bourguignon (
Date: 04/26/05

Date: Tue, 26 Apr 2005 08:36:01 +0200 (Niraj123) writes:

> I created a child process by using fork() system call.
> Now i am interested to stop the child process when the parent dies. I
> don't want the child process to be adopted by init process.
> e.g when i use kill -9 pid
> in that case i want to kill the child of the (pid) process.

You should start a process group at the parent process so the child be
in the same process group (instead of being in that of the grand

man setpgid

I guess calling: setpgid(0,0); in the parent would do it.

Normally, don't use kill -9. Use the normal kill to leave time to the
process to clean up cleanly. Only if it doesn't terminate in a
reasonable time you may kill -9.
( kill -TERM $pid ; sleep 15 ; kill -KILL $pid )
Note that if the process is doing I/O (eg. is in the kernel, 'D' state
in ps(1)) then it won't disappear anyway until this I/O terminates
(which may take a long time if it involves NFS for example).

__Pascal Bourguignon__           
In a World without Walls and Fences, 
who needs Windows and Gates?