更新时间:2023-12-03 20:35:28
如果某些管道(2)是关闭( 2) -ed,进一步 write(2)将会得到SIGPIPE
signal(7).另请阅读 pipe(7).
If the read end of some pipe(2) is close(2)-ed, further write(2)s will get a SIGPIPE
signal(7). Read also pipe(7).
当管道缓冲区已满时,他们将获得SIGPIPE
.
在yes | ./readstdin
命令中,yes
命令获得一个SIGPIPE
信号.只需在终端中尝试yes
,它会无限期地吐出一些恶作剧内容,直到您将其杀死为止.
In the yes | ./readstdin
command, the yes
command gets a a SIGPIPE
signal. Just try yes
in a terminal, it spits some output indefinitely ad nauseam till you kill it.
在cat file | ./readstdin
命令中,可能会发生(特别是如果file
很小,小于sysconf(_POSIX_PIPE_BUF)
字节,可能是4096字节),则cat
命令是close(2)
- STDOUT_FILENO
描述符,并且管道仍未满.那么cat
可能不会得到任何SIGPIPE
.
In the cat file | ./readstdin
command, it could happen (notably if file
is quite small, less that sysconf(_POSIX_PIPE_BUF)
bytes, which might be 4096 bytes), that the cat
command is close(2)
-ing the STDOUT_FILENO
descriptor and that the pipe is still not full. Then cat
may not get any SIGPIPE
.