Hi I m trying to execute small code in python , it is giving OS error.
>>> import os
>>> def child():
... pid = os.fork()
... if not pid:
... for i in range(5):
... print i
... return os.wait()
...
>>> child()
0
1
2
3
4
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 6, in child
OSError: [Errno 10] No child processes
I m not able to figure out why it is giving OSError. I googled it and it is noted as bug for python 2.6 or before. I’m using python2.7.
You missed an else. Thus, you are calling
os.wait()in children processes (who have no children of their own, hence the error).Corrected code below: