Re: Why doesn't kill work?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2005-02-21 at 00:21 -0500, Deron Meranda wrote:
> On Sun, 20 Feb 2005 23:46:56 -0500, Scot L. Harris <webid@xxxxxxxxxx> wrote:
> > So if the parent process crashes all of the child processes will be
> > cleared?
> 
> When a parent process dies, all of it's children (whether currently
> running or if they're zombies), are "inherited" by the main init
> process, always process ID 1.  And init will always immediately reap
> any zombies.  (Init is really a fake process which serves as the
> process-face to the kernel itself.)  So in effect, if the parent process
> of a zombie dies, then the zombies will immediately be reaped and
> disappear almost immediately.
> 
> 

NOT always.  Some processes leave zombies that last forever (until the
next reboot).

> >  I thought the parent process had to issue an _exit() (or
> > something similar) to get the child process status so it would exit
> > cleanly.
> 
> The parent needs to call one of the wait() system calls [which
> includes wait(), waitpid(), wait3(), wait4()].  That will return
> to the parent the exit code that the kernel has been remembering;
> and which also "reaps" the zombie and makes it disappear.
> [Or, instead, the parent can tell the kernel to do auto-reaping
> via the SA_NOCLDWAIT signal action flag.]
> 
> The exit() call is performed by a child process when it wishes
> to pass back a specific exit code.  This is done automatically
> in C/C++ when a return is made from main().  But, even if a
> child doesn't call exit() because it terminated some other way
> (like a core dump), the parent must still call wait().
> 
> It can be a little trickier on Linux, especially if you start
> talking about advanced subjects like multithreaded processes
> and the clone() system call.  But the most common case
> is the child calls exit() and the parent calls wait().  The
> time in between the two calls is when a zombie exists.
> 
> 
> >  If it did not do that then the child process sits around
> > waiting for the parent which is no longer running so it stays forever.
> 
> When a child dies, it dies.  It doesn't need to wait around on
> any other process.  Of course a zombie may result, which only
> means that the parent hasn't yet recognized that the child has
> died.   The only exception is when the child process is currently
> being traced (such as being debugged)..in which case the
> tracing program must detach before the child actually dies.
> 
> -- 
> Deron Meranda
> 


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux