preforkunix.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:SoCFoundationFlow 作者: mattaw 项目源码 文件源码
def make_conn(bld):
        child_socket, parent_socket = socket.socketpair(socket.AF_UNIX)
        ppid = os.getpid()
        pid = os.fork()
        if pid == 0:
            parent_socket.close()

            # if the parent crashes, try to exit cleanly
            def reap():
                while 1:
                    try:
                        os.kill(ppid, 0)
                    except OSError:
                        break
                    else:
                        time.sleep(1)
                os.kill(os.getpid(), signal.SIGKILL)
            t = threading.Thread(target=reap)
            t.setDaemon(True)
            t.start()

            # write to child_socket only
            try:
                while process_command(child_socket):
                    pass
            except KeyboardInterrupt:
                sys.exit(2)
        else:
            child_socket.close()
            return (pid, parent_socket)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号