[plt-scheme] custodian + process/ports
> 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))
(let-values
(((proc
stdout
stdin
stderr) (apply subprocess
devnull #f devnull
"/usr/local/bin/dfork"
cmdline)))
(subprocess-wait proc)
stdin))
// dfork.c:
#include <unistd.h>
int main (int argc, char **argv) {
int pid = fork();
if (!pid) {
argc--;
argv++;
char *a[argc];
int i;
for (i=0; i<argc; i++){
a[i] = argv[i];
}
a[i] = 0;
execvp(a[0], a);
}
return 0;
}