fork problem
守株待兔
1248283536 at qq.com
Fri Aug 12 10:18:52 EDT 2011
in the book ,A call to wait() suspends execution (i.e., waits) until a child process (any child process) has completed, terminating either normally or via a signal. wait() will then reap the child, releasing any resources. If the child has already completed, then wait() just performs the reaping procedure.
here is my code
import os
print "i am parent ",os.getpid()
ret = os.fork()
print "i am here",os.getpid()
if ret == 0:
os.system('ls')
else:
os.wait()
print "i am runing,who am i? ",os.getpid()
according to the word,the output may be:
i am parent 8014
i am here 8014
i am here 8015
"omitted my file"
i am runing,who am i? 8014
because 8015 is terminated by os.wait().
in fact the output is:
i am parent 8014
i am here 8014
i am here 8015
"omitted my file"
i am runing,who am i? 8015
i am runing,who am i? 8014
i want to know why ??
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110812/7f5f003d/attachment.html>
More information about the Python-list
mailing list