os.fork leaving processes behind

Discussion in 'Python' started by Falcolas, Dec 28, 2007.

  1. Falcolas

    Falcolas Guest

    Hi all,

    This may be more of a Linux question, but it relates to how Python
    forks...

    Today, I implemented a pretty simple listener script using os.fork.
    The script runs fine, and performs as expected, but the process table
    is left with an odd entry for every fork called.

    I'm running on Slackware 9, under the 2.4 kernel, Python 2.5.1.

    while True:
    conn, addr = s.accept()
    if os.fork():
    continue
    else:
    handle_connection(conn)
    sys.exit(0)

    Running ps -ef results in a slew of '[ python <depreciated> ]' entries
    (or something similar, I no longer have the actual output).

    Will these clean themselves up if I leave the process running, and
    what causes these?

    Thanks in advance, G
    Falcolas, Dec 28, 2007
    #1
    1. Advertising

  2. En Thu, 27 Dec 2007 21:36:36 -0300, Falcolas <> escribió:

    > This may be more of a Linux question, but it relates to how Python
    > forks...


    Yes; every book describing how to use fork tells about zombie processes
    and the wait/waitpid functions. Just do the same thing in Python.

    > Today, I implemented a pretty simple listener script using os.fork.
    > The script runs fine, and performs as expected, but the process table
    > is left with an odd entry for every fork called.


    A "zombie".

    > I'm running on Slackware 9, under the 2.4 kernel, Python 2.5.1.
    >
    > while True:
    > conn, addr = s.accept()
    > if os.fork():
    > continue
    > else:
    > handle_connection(conn)
    > sys.exit(0)


    I'd try to use any of the existing server implementations in
    SocketServer.py, but if you insist on using your own, look at the
    ForkingMixin class as an example of using waitpid() to avoid having zombie
    processes.

    --
    Gabriel Genellina
    Gabriel Genellina, Dec 28, 2007
    #2
    1. Advertising

  3. Falcolas

    Falcolas Guest

    On Dec 28, 12:11 am, "Gabriel Genellina" <>
    wrote:
    > I'd try to use any of the existing server implementations in
    > SocketServer.py, but if you insist on using your own, look at the
    > ForkingMixin class as an example of using waitpid() to avoid having zombie
    > processes.
    >
    > --
    > Gabriel Genellina


    Thanks for the excellent advice. I went with the SocketServer, and I'm
    quite happy with the results. I had not considered it earlier due to
    the atrocious documentation on the Python site. Google helped with
    that immensely.

    G
    Falcolas, Dec 31, 2007
    #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. Sabre
    Replies:
    1
    Views:
    308
    Stefan Behnel
    Mar 21, 2006
  2. Eric Snow

    os.fork and pty.fork

    Eric Snow, Jan 8, 2009, in forum: Python
    Replies:
    0
    Views:
    563
    Eric Snow
    Jan 8, 2009
  3. diablo
    Replies:
    18
    Views:
    233
    Roland Hall
    Jul 4, 2005
  4. Michele Dondi

    A problem with fork() and managing processes

    Michele Dondi, Dec 1, 2004, in forum: Perl Misc
    Replies:
    7
    Views:
    124
    Michele Dondi
    Dec 3, 2004
  5. Guest

    Fork, processes and exit codes?

    Guest, Feb 3, 2005, in forum: Perl Misc
    Replies:
    0
    Views:
    105
    Guest
    Feb 3, 2005
Loading...

Share This Page