Kill forked processes

Discussion in 'Python' started by kmkz, Feb 26, 2006.

  1. kmkz

    kmkz Guest

    Hi,

    I have a program A that forks off two other programs, B and C. I need B
    and C to both terminate if A is closed, but by using the
    subprocess.call() method this seems to not be the case; I can shut down
    the "black box" that is program A and B/C will still stay up.

    How can I achieve the desired behavior?

    Thanks,
    Evan
     
    kmkz, Feb 26, 2006
    #1
    1. Advertising

  2. kmkz wrote:

    > I have a program A that forks off two other programs, B and C. I need B
    > and C to both terminate if A is closed, but by using the
    > subprocess.call() method this seems to not be the case; I can shut down
    > the "black box" that is program A and B/C will still stay up.
    >
    > How can I achieve the desired behavior?


    You'll probably need to take a look at the `signal' and `atexit' modules.
    These will allow you to write hooks that will get called when your A script
    is terminated either by a signal or by reaching one of the "natural"
    endpoints.

    --
    Steve Juranich
    Tucson, AZ
    USA
     
    Steve Juranich, Feb 26, 2006
    #2
    1. Advertising

  3. kmkz

    kmkz Guest

    Thank you for your reply. I will certainly look into those.

    Another question:

    Lets say my script A executes two other scripts, B and C. B is a Python
    file compiled into an exe and uses the regular black box. C, however,
    is a C++ program that I did not write, and have no access to (besides
    executing it. ie, i don't have its source). I would like to fork off
    the process B and C from A, but make B and C invisible and unable to be
    shut down by the user. This way, they have to kill process A.
    Unfortunately, this brings me back to the problem I posted above: how
    to make the subprocesses dependant on its parent process. Since I have
    no access to the C++ program's source I need to come up with a better
    way of forcing the OS to "see" process B as being inside of process C
    and then shut it down, deallocate its memory, close its pipes, etc...

    Any ideas?

    I'll be willing to PayPal $10 to anyone who completely figures this out
    for me :)
     
    kmkz, Feb 27, 2006
    #3
  4. kmkz wrote:

    > Lets say my script A executes two other scripts, B and C. B is a Python
    > file compiled into an exe and uses the regular black box. C, however,
    > is a C++ program that I did not write, and have no access to (besides
    > executing it. ie, i don't have its source). I would like to fork off
    > the process B and C from A, but make B and C invisible and unable to be
    > shut down by the user. This way, they have to kill process A.
    > Unfortunately, this brings me back to the problem I posted above: how
    > to make the subprocesses dependant on its parent process. Since I have
    > no access to the C++ program's source I need to come up with a better
    > way of forcing the OS to "see" process B as being inside of process C
    > and then shut it down, deallocate its memory, close its pipes, etc...
    >
    > Any ideas?


    Again, the atexit and signal modules will be your friend.

    > I'll be willing to PayPal $10 to anyone who completely figures this out
    > for me :)


    1) I wouldn't want to spoil the fun.
    2) My time writing code costs much more than that. :)

    --
    Steve Juranich
    Tucson, AZ
    USA
     
    Steve Juranich, Feb 27, 2006
    #4
  5. kmkz

    kmkz Guest

    I didn't mean that you'd have to write it for me, I meant that if what
    you said works (atexit, signal) I will paypal you $10 for your generous
    contribution to my project.
     
    kmkz, Feb 27, 2006
    #5
    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. Alexander N. Spitzer
    Replies:
    1
    Views:
    533
    Lawrence Kirby
    Nov 12, 2004
  2. Pierre Morel
    Replies:
    5
    Views:
    123
    Pierre Morel
    Feb 17, 2010
  3. Tim Uckun
    Replies:
    12
    Views:
    287
    Tim Uckun
    Oct 14, 2010
  4. Stéphane Métais

    Kill forked process on Windows 2000

    Stéphane Métais, Oct 17, 2003, in forum: Perl Misc
    Replies:
    3
    Views:
    216
    sandor
    Oct 22, 2003
  5. Moritz Karbach

    How to kill a forked child process...

    Moritz Karbach, Jun 17, 2005, in forum: Perl Misc
    Replies:
    11
    Views:
    424
    Moritz Karbach
    Jun 20, 2005
Loading...

Share This Page