什么设置了孩子的 STDERR、STDOUT 和 STDIN?

Eva*_*oll 4 file-descriptors fork

如果一个程序运行fork()什么设置标准流STDOUTSTDINSTDERR

Kyl*_*nes 7

标准输入、标准输出和标准错误是从父进程继承的。如果需要,由子进程将它们更改为指向新文件。

fork(2)手册页:

   *  The  child inherits copies of the parent's set of open file descrip?
      tors.  Each file descriptor in the child refers  to  the  same  open
      file  description (see open(2)) as the corresponding file descriptor
      in the parent.
Run Code Online (Sandbox Code Playgroud)