简体   繁体   中英

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. Here is a python code the fork a child process

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.

Your understanding would be correct if you had used os.fork() instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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