I saw these code in a book Programming Python:
import os
parm = 0
while True:
parm += 1
pid = os.fork()
if pid == 0: # copy process
os.execlp('python', 'python', 'child.py', str(parm)) # overlay program
assert False, 'error starting program' # shouldn't return
else:
print('Child is', pid)
if input() == 'q': break
Why there are two pythons in os.execlp
? And it seems that the second one can be any string. What does the second argument do?
Edit: I still don't understand after reading the possibly duplicated question. This is child.py:
import os, sys
print('Hello from child', os.getpid(), sys.argv[1])
So argv[1]
is str(parm)
, argv[0]
is child.py, isn't it?