Re: [gtk-list] Re: fork() / execl()



On Tue, 25 May 1999 11:08:56 +0200 (MET DST), gtk-list@redhat.com (Emmanuel DELOGET) wrote:
> As the well known Daniel J. Kressin said...
> ->Also, the child should exit with _exit() rather
> ->than exit(), correct?
> 
>      Exit() just works until you don't register atexit function
>      that free() something wrong (and so on). Basically, exit()
>      calls all atexit registered functions, flushes streams, closes
>      opened streams, destroy temp files than calls _exit(), which
>      close opened FDs, send SIGCHLD to its parent (if one exists),
>      do some tricky stuff to have its sons be the init daemon sons,
>      and send SIGHUP and SIGCONT to others.

[note: this is becoming off topic, but it's fun ;-)]

After the atexit functions, everything is handled by the kernel. So the
kernel closes all FDs which are still open, sends a SIGCHLD to its parent.
The parent has to call wait() or waitpid() to get the exit status of the
child (this can be done in a SIGCHLD signal handler). As long as the
parent doesn't collect the status of the child, the child's process table
will be kept in memory by the kernel; that's what we call a zombie
process.

The tricky stuff about the child's child processes isn't tricky at all:
In a process table entry is a list of its child processes. If a process
dies, the kernel cleans up it's process table, and set the PPID (parent
process ID) of each child to the PPID of the parent's parent
(grandparent). If the grandparent also died, they will get the PPID of the
grandparent's parent (greatgrandparent). As init is the "mother of all
processes" and supposed to run forever, init will clean up all zombies.

I'm not sure if the kernel also sends SIGHUP/SIGCONT to the child
processes, I can't find evidence[1] on that. My experience is that it
doesn't.


Erik

[1] W. Richard Stevens, "Advanced programming in the UNIX environment",
    Addison-Wesley

-- 
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031,  2600 GA Delft, The Netherlands
Phone: +31-15-2785859  Fax: +31-15-2781843  Email J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/




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