Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > os.fork leaving processes behind

Reply
Thread Tools

os.fork leaving processes behind

 
 
Falcolas
Guest
Posts: n/a
 
      12-28-2007
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
 
Reply With Quote
 
 
 
 
Gabriel Genellina
Guest
Posts: n/a
 
      12-28-2007
En Thu, 27 Dec 2007 21:36:36 -0300, Falcolas <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
 
Falcolas
Guest
Posts: n/a
 
      12-31-2007
On Dec 28, 12:11 am, "Gabriel Genellina" <(E-Mail Removed)>
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Leaving The Past Behind Lawrence D'Oliveiro NZ Computing 0 03-02-2011 11:07 AM
Controlling processes and what to "feed" other processes Marc Heiler Ruby 1 05-24-2009 05:37 PM
Re: Is Netscape Leaving Firefox Behind on GNU/Linux? THE LINUX PROPAGANDA MACHINE CONTINUES. FIREFOX IGNORING LINUX............. traci.manicotti@gmail.com Computer Support 2 10-20-2007 02:12 PM
removin html tags from string - but leaving a few behind diablo ASP General 18 07-04-2005 12:42 PM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM



Advertisments