for 与 ipc

来源:互联网 发布:r330清零软件 编辑:程序博客网 时间:2024/05/21 22:46
#!/usr/bin/python# Filename:using_fork.py import os, sys print "I'm going to fork now" r, w = os.pipe() pid = os.fork() if pid:    # parent    os.close(w)    r = os.fdopen(r)     print "parent: reading"    txt = r.read()    os.waitpid(pid, 0) else:    # child    os.close(r)    w = os.fdopen(w, 'w')    print "child:writing"    w.write("here's some text from the child")    w.close()    print "child:closing"    sys.exit(0)


jobin@jobin-desktop:~/work/python/fork$ python using_fork.pyI'm going to fork nowparent: readingchild:writingchild:closing