Re: How to kill child & parent process simulanteously

From: Pascal Bourguignon (pjb_at_informatimago.com)
Date: 04/26/05


Date: Tue, 26 Apr 2005 08:36:01 +0200

niraj.kumar.ait@gmail.com (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
parent).

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__                     http://www.informatimago.com/
In a World without Walls and Fences, 
who needs Windows and Gates?


Relevant Pages

  • Help with Fork/Exec
    ... I'm dabbling in forkand execfor the first time and have ... to start my parent program, execute a child process, kill it, then ... I'm then able to kill it without a problem. ... However, when I go to start the child process a second time, my parent ...
    (comp.unix.programmer)
  • Re: Help with Fork/Exec
    ... I'm dabbling in forkand execfor the first time and have ... to start my parent program, execute a child process, kill it, then ... I'm then able to kill it without a problem. ... However, when I go to start the child process a second time, my parent ...
    (comp.unix.programmer)
  • Re: Help with Fork/Exec
    ... In a simplified test case, ... to start my parent program, execute a child process, kill it, then ... I'm then able to kill it without a problem. ... However, when I go to start the child process a second time, my parent ...
    (comp.unix.programmer)
  • Re: How to kill child & parent process simulanteously
    ... >> I created a child process by using fork() system call. ... >> Now i am interested to stop the child process when the parent dies. ... You could have the parent become a process group leader, and then kill ...
    (comp.unix.programmer)
  • Re: vms versus solaris
    ... >> between Symbols and Logicals as I really thought they were pretty much ... A shell symbol that needs to be visible to a child process and/or ... Environment variables are passed down by child processes. ... child process are _NOT_ visible to the parent. ...
    (comp.os.vms)