Orphaned child processes

Discussion in 'Python' started by rocco.rossi@gmail.com, Apr 7, 2008.

  1. Guest

    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.
     
    , Apr 7, 2008
    #1
    1. Advertising

  2. John Nagle Guest

    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
     
    John Nagle, Apr 7, 2008
    #2
    1. Advertising

  3. Donn Cave Guest

    In article <47fa650f$0$36329$>,
    John Nagle <> wrote:

    > 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,
     
    Donn Cave, Apr 8, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rhett

    Orphaned Excel 97 Instances (C#)

    rhett, Dec 2, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    2,114
    rhett
    Dec 2, 2004
  2. Replies:
    0
    Views:
    467
  3. newspost2000

    Finding Orphaned Files On A Website

    newspost2000, Feb 8, 2006, in forum: HTML
    Replies:
    10
    Views:
    7,673
  4. george1069 george1069

    Orphaned table-header help...

    george1069 george1069, Apr 3, 2005, in forum: XML
    Replies:
    0
    Views:
    440
    george1069 george1069
    Apr 3, 2005
  5. Jeff Rodriguez
    Replies:
    23
    Views:
    1,200
    David Schwartz
    Dec 9, 2003
Loading...

Share This Page