Orphaned child processes

John Nagle nagle at animats.com
Mon Apr 7 14:27:48 EDT 2008


rocco.rossi at gmail.com wrote:
> I'm using the Python processing module. I've just run into a problem
> though. Actually, it's a more general problem that isn't specific to
> this module, but to the handling of Unix (Linux processes) in general.
> Suppose for instance that for some reason or another, after forking
> several child processes, the main process terminates or gets killed
> (or segfaults or whatever) and the child processes are orphaned. Is
> there any way to automatically arrange things so that they auto-
> terminate or, in other words, is there a way to make the child
> processes terminate when the parent terminates?
> 
> Thank you.

    Put a thread in the child which reads stdin, and make stdin
connect to a pipe from the parent.  When the parent terminates,
the child will get a SIGPIPE error and raise an exception.

				John Nagle



More information about the Python-list mailing list