os.fork() question?

I

Ishwar Rattan

Info at http://doc.python.org/ on os.fork() says that
it has 'unix' semantics (on a UNIX box) on return values
child pid in parent, 0 in child, no mention of failure?

So, what does it return on failure? I tried it under Linux
with Python-2.3.4, after few thousand forks the system just hangs!
(does not return/report fork failure)

Another question on module 'mutex' (stumbuled on it while looking
for info on threads). What is its purpose? (sample code for usage
of lock() and unlock() will be nice too).

-ishwar
 
E

Erik Heneryd

Ishwar said:
Info at http://doc.python.org/ on os.fork() says that
it has 'unix' semantics (on a UNIX box) on return values
child pid in parent, 0 in child, no mention of failure?

So, what does it return on failure? I tried it under Linux
with Python-2.3.4, after few thousand forks the system just hangs!
(does not return/report fork failure)

It raises OSError.


Erik
 
I

Ishwar Rattan

Erik Heneryd said:
It raises OSError.


Erik
The following code when executed kills controlling xterm+X-window system,
but the system does not hang.

-ishwar
---
import os, signal, sys, time

def child():
signal.pause()
print 'this from child with pid: ', os.getpid()
sys.exit(2)

def main():
print 'forking child..'
while 1:
try:
cpid = os.fork()
except OSError:
raise 'fork failed..'
if cpid == 0:
child()
else:
print 'fork success..', cpid

main()
-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,206
Messages
2,571,069
Members
47,675
Latest member
RollandKna

Latest Threads

Top