Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Orphaned child processes

Reply
Thread Tools

Orphaned child processes

 
 
rocco.rossi@gmail.com
Guest
Posts: n/a
 
      04-07-2008
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.
 
Reply With Quote
 
 
 
 
John Nagle
Guest
Posts: n/a
 
      04-07-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
 
Donn Cave
Guest
Posts: n/a
 
      04-07-2008
In article <47fa650f$0$36329$(E-Mail Removed)>,
John Nagle <(E-Mail Removed)> wrote:

> (E-Mail Removed) 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


That could work, but not precisely in that manner. You get
SIGPIPE when you write to a closed pipe. When you read from one,
you get end of file, i.e., a normal return with 0 bytes.

When you test it, make sure to try a configuration with more
than one child process. Since the parent holds the write end
of the pipe, subsequently forked child processes could easily
inherit it, and they'll hold it open and spoil the effect.

Donn Cave, (E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding Orphaned Files On A Website newspost2000 HTML 10 01-03-2013 12:03 PM
Link validation and finding orphaned files newspost2000@yahoo.com HTML 0 02-07-2006 09:15 PM
Orphaned table-header help... george1069 george1069 XML 0 04-03-2005 03:59 PM
Orphaned Excel 97 Instances (C#) rhett ASP .Net 0 12-02-2004 06:25 PM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM



Advertisments