Proc::Background killing parent process when child dies

Discussion in 'Perl Misc' started by Paul Clements, Feb 10, 2004.

  1. Hi,

    I have a perl script which spawns processes by use of Proc::Background
    and this works fine.

    One of the child processes accesses a database and if that database is
    down I want as well as the child process to die, I want the parent
    process to exit.

    Any clues on how to do this would be very much appreciated

    Regards

    Paul
     
    Paul Clements, Feb 10, 2004
    #1
    1. Advertising

  2. Paul Clements

    Guest

    Paul Clements <> wrote:
    > Hi,
    >
    > I have a perl script which spawns processes by use of Proc::Background
    > and this works fine.
    >
    > One of the child processes accesses a database and if that database is
    > down I want as well as the child process to die, I want the parent
    > process to exit.
    >
    > Any clues on how to do this would be very much appreciated
    >
    > Regards
    >
    > Paul


    I've never used Proc::Background, but in a fork() environment, you can store
    the parent process ID to a variable (prior to fork()) and then from the child
    send a signal to the parent. kill($PARENT_PID,<whatever_signal>); If you've
    got multiple child processes, you'll probably want the parent to tell the
    other child procs to exit as well. (just use an event handler in
    the %SIG array to do this.)

    Jamie
     
    , Feb 11, 2004
    #2
    1. Advertising

  3. Paul Clements

    Ben Morrow Guest

    (Paul Clements) wrote:
    > I have a perl script which spawns processes by use of Proc::Background
    > and this works fine.
    >
    > One of the child processes accesses a database and if that database is
    > down I want as well as the child process to die, I want the parent
    > process to exit.
    >
    > Any clues on how to do this would be very much appreciated


    If you're on a Unix system, catch SIGCHLD and check it against a list
    of spawned processes.

    Ben

    --
    Musica Dei donum optimi, trahit homines, trahit deos. |
    Musica truces molit animos, tristesque mentes erigit. |
    Musica vel ipsas arbores et horridas movet feras. |
     
    Ben Morrow, Feb 11, 2004
    #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. David Lozzi
    Replies:
    3
    Views:
    1,949
    David Lozzi
    Jun 1, 2005
  2. Дамјан ГеоргиевÑки

    end child process when parent dies (on Unix)

    Дамјан ГеоргиевÑки, Nov 17, 2008, in forum: Python
    Replies:
    4
    Views:
    663
    Miles
    Nov 18, 2008
  3. Chris Angelico
    Replies:
    6
    Views:
    469
    Dan Stromberg
    Dec 7, 2011
  4. Марк Коренберг

    Multiprocessing: killing children when parent dies

    Марк Коренберг, Oct 18, 2013, in forum: Python
    Replies:
    2
    Views:
    98
    Ricardo Aráoz
    Oct 18, 2013
  5. Terry Reedy
    Replies:
    0
    Views:
    106
    Terry Reedy
    Oct 18, 2013
Loading...

Share This Page