forking and avoiding zombies!

Discussion in 'Python' started by andrea crotti, Dec 10, 2012.

  1. So I implemented a simple decorator to run a function in a forked
    process, as below.

    It works well but the problem is that the childs end up as zombies on
    one machine, while strangely
    I can't reproduce the same on mine..

    I know that this is not the perfect method to spawn a daemon, but I
    also wanted to keep the code
    as simple as possible since other people will maintain it..

    What is the easiest solution to avoid the creation of zombies and
    maintain this functionality?
    thanks


    def on_forked_process(func):
    from os import fork
    """Decorator that forks the process, runs the function and gives
    back control to the main process
    """
    def _on_forked_process(*args, **kwargs):
    pid = fork()
    if pid == 0:
    func(*args, **kwargs)
    _exit(0)
    else:
    return pid

    return _on_forked_process
     
    andrea crotti, Dec 10, 2012
    #1
    1. Advertisements

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. Robert Brewer

    CGI zombies with Apache 1.3 on Linux

    Robert Brewer, Dec 10, 2004, in forum: Python
    Replies:
    1
    Views:
    488
    Erik Max Francis
    Dec 10, 2004
  2. jsnx

    the secret life of zombies

    jsnx, Oct 12, 2007, in forum: Python
    Replies:
    2
    Views:
    324
  3. jsnx

    the secret life of zombies

    jsnx, Oct 12, 2007, in forum: Python
    Replies:
    0
    Views:
    331
  4. bitcycle
    Replies:
    3
    Views:
    551
    Nobody
    Jul 7, 2011
  5. Rex Gustavus Adolphus
    Replies:
    5
    Views:
    341
    Rex Gustavus Adolphus
    Jul 4, 2003
  6. Uri Guttman

    perl zombies

    Uri Guttman, Aug 16, 2003, in forum: Perl Misc
    Replies:
    17
    Views:
    316
    Hudson
    Aug 25, 2003
  7. andrea crotti

    Re: forking and avoiding zombies!

    andrea crotti, Dec 11, 2012, in forum: Python
    Replies:
    1
    Views:
    171
    Nobody
    Dec 12, 2012
  8. peter
    Replies:
    1
    Views:
    177
    Thomas Rachel
    Dec 11, 2012
Loading...