什么是非标准输入/输出/错误

Tra*_*iet 2 stdout stdin stderr

我读过提到标准输入/输出/错误的书籍/教程。我的理解是:

  1. standard input/output/error are concepts of a process (i.e. if someone mentions standard input/output/error, they are actually talking about standard input/output/error of a particular process. It doesn't make sense to talk about standard input/output/error of a file.)
  2. Standard input in Linux for most processes is keyboard and standard output/error is screen.

My question: if there's the standard, what is the non-standard input/output/error of a process in Linux?

Rud*_*diC 7

文件描述符0,1和默认提供2时的处理execED和相关联stdinstdoutstderr。如果进程需要额外的 I/O 通道,它会打开从 3 开始的非标准文件描述符。

对于 1.:是的

对于 2.:对于不重定向 I/O 的交互式进程来说是这样。其他进程(例如cron作业)可能有不同的关联。

  • 对于 2,我会说这是“大多数进程”从自己的标准文件描述符是终端的 shell 启动的结果。*所有*进程从其父进程继承标准文件描述符。(即使重定向也是对 shell 的指令,用于替换其他描述符来代替 shell 自己的描述符。进程不知道*如何*设置自己的标准描述符。) (2认同)