[plt-scheme] subprocess: double fork() to avoid zombies

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Jul 21 11:59:34 EDT 2009

I think a better solution is to have MzScheme call wait() in the
scheduler after any SIGCHLD. The check_child_done() function already
handles any terminating child and records its exit status.

At Tue, 21 Jul 2009 17:42:00 +0200, Tom Schouten wrote:
> Hello,
> 
> I'd like to pick up this thread:
> http://list.cs.brown.edu/pipermail/plt-scheme/2008-July/025637.html
> 
> On Tue Jul 1 2008, Eli Barzilay wrote:
> > My guess would be that the subprocess object gets released, but the
> > process is still alive, which leads to the zombie.  (The main problem
> > being that custodians manage memory & ports, but not processes.)
> 
> I was wondering if it is possible to extend `subprocess' with
> a double fork() mechanism.  I had a look at the code in
> plt/src/mzscheme/src/port.c and it seems it should be
> straightforward.  Something like this:
> 
> [mzscheme]--fork()-+-------wait()-----------------+--------->
>                    |                              |
>                    +--cleanup()--fork()-+--exit()-+
>                                         |
>                                         +--exec()-[child]---> 
> 
> in addition to the current behaviour:
> 
> [mzscheme]--fork()-+---------------------------------------->
>                    |                              
>                    +--cleanup()------------exec()-[child]--->
> 
> 
> The idea being that in a lot of practical cases you don't
> care about a child's exit status.  Doing it like this still
> allows you to shut down a child by closing its input port,
> which by most tools is interpreted as "exit", without ever
> having to care about zombie processes caused by not performing
> wait().
> 
> I'd try this using the FFI but it seems the cleanup()
> functionality in port.c would have to be duplicated.
> 
> Cheers,
> Tom
> 
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme


Posted on the users mailing list.