[plt-scheme] custodian + process/ports

From: Tom Schouten (tom at zwizwa.be)
Date: Wed Jul 2 07:51:27 EDT 2008

> 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 tried a double fork workaround, which seems to work. The process terminates
when its stdin is closed, but doesn't become a zombie because it is a child
of init due to the death of its parent.

This is probably easier to do with the FFI so no external process is necessary.

(define (open-output-process . cmdline)
  (define devnull (open-output-file "/dev/null" #:exists 'append))
         stderr) (apply subprocess
                        devnull #f devnull
    (subprocess-wait proc)

// dfork.c:

#include <unistd.h>
int main (int argc, char **argv) {
    int pid = fork();
    if (!pid) {
        char *a[argc];
        int i;
        for (i=0; i<argc; i++){
            a[i] = argv[i];
        a[i] = 0;
        execvp(a[0], a);
    return 0;

Posted on the users mailing list.