fork problem
aspineux
aspineux at gmail.com
Fri Aug 12 10:30:57 EDT 2011
On Aug 12, 4:18 pm, "守株待兔" <1248283... at qq.com> wrote:
> 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 ??
To get what you want, use os.exec() instead of os.system()
or add a os.exit() just after os.system()
Regards
More information about the Python-list
mailing list