简体   繁体   English

对于派生进程,stdout和stdin会发生什么?

[英]What happens to the stdout and stdin for a forked process?

I understand the fork function.I know that it duplicates the parent process and after the fork function has been called the parent complete its execution and the child start its execution. 我了解fork函数,我知道它复制了父进程,并且在调用fork函数后,父进程完成了执行,子进程开始了执行。 Here is a python code the fork a child process 这是一个python代码的fork子进程

import os
pid, master_fd =os.forkpty()
if pid == 0:
    print ('child')
else:
   print ('parent') 

Why is the word child doesn't get printed?? 为什么孩子这个词没有被印出来?

The word "child" doesn't appear because os.forkpty() creates a new pseudo-terminal and routes the child's output to it. 因为os.forkpty()创建了一个新的伪终端,并将子os.forkpty()的输出路由到它,所以没有出现“子os.forkpty() ”一词。

Your understanding would be correct if you had used os.fork() instead. 如果您使用os.fork()代替,您的理解将是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM