标准输入
- this is the
文件处理
你的程序会读取这些信息,以获取你的信息。
标准输出
- your process writes conventional output to this 文件处理.
标准误差
- your process writes diagnostic output to this 文件处理.
这已经是我能做到的最简单的了 :-)
Of course, that's mostly by convention. There's nothing stopping you from writing your diagnostic information to standard output if you wish. You can even close the three 文件处理s totally and open your own files for I/O.
当你的进程启动时,它应该已经打开了这些句柄,它可以直接从它们中读取和/或写入。
默认情况下,它们可能连接到你的终端设备上(例如,
/dev/tty
),但shells将允许你在你的进程开始之前,在这些句柄和特定的文件和/或设备(甚至到其他进程的管道)之间建立连接(一些可能的操作是相当巧妙的)。
一个例子是。
my_prog <inputfile 2>errorfile | grep XYZ
which will:
create a process for my_prog
.
open inputfile
as your standard input (文件处理 0).
open errorfile
as your standard error (文件处理 2).
create another process for grep
.
attach the standard output of my_prog
to the standard input of grep
.
Re your comment:
当我在/dev文件夹中打开这些文件时,怎么从来没有看到一个进程运行的输出?
这是因为它们不是正常的文件。虽然UNIX提出了everything作为文件系统中某处的一个文件,这并不意味着它在最底层也是如此。在/dev
层次中的大多数文件是字符或块设备,实际上是一个设备驱动程序。它们没有大小,但它们有一个主要和次要的设备编号。
当你打开它们时,你连接到设备驱动程序,而不是一个物理文件,而且设备驱动程序足够聪明,知道独立的进程应该被分开处理。
Linux的/proc
文件系统也是如此。那些并不是真正的文件,只是严格控制的通往内核信息的通道。