. a.py ( os.system ) , a.py , . PID b.py , , a.py , b.py - - PID b.py 1, init.
, , . , run.py, a.py . , , read() .
run.py, , :
import os
from time import sleep
print("Started run.py")
r, w = os.pipe()
pid = os.fork()
if pid == 0:
os.close(r)
os.execlp("./a.py", "./a.py")
os._exit(127)
os.close(w)
os.waitpid(pid, 0)
print("a is ready.")
os.read(r, 1)
os.close(r)
print("Now all messages should be there.")
:
Pipe - , . , , , , , , . ( , , stdin stdout, .)
, . , , . , , , . , , , a.py. , , , . , os.read() 0, .
:
os.pipe() print os.system(), , . ( - os.system() , .)
os.fork() , PID ( 0, PID, os.getpid()).
if pid == 0: execs ./a.py. "Exec" , , . os._exit() , execlp (, Python, execlp , , ). .
( ). os.waitpid(pid) - a.py, os.system(). waitpid, , .
os.read(r, 1), : 1 . , , . a.py , - , . , os.read() , .
, , .