问题描述
这是一个管道命令随机产生10个字符的密码:
This is a piped command for generating 10 characters password at random:
cat /dev/urandom | base64 | head -c 10
我的问题是猫的/ dev / urandom的| BASE64
是一个无限的输出流将无法自动停止。但是,为什么追加头-c 10
使得整个管道终止?我假设猫
,的base64
和头
的3分离过程,怎么能头
终止猫
?
My question is cat /dev/urandom | base64
is an infinite output stream which will not stop by itself. But why appending head -c 10
makes the whole pipe terminated? I assume cat
, base64
and head
are 3 separated processes, how can head
terminate the cat
?
推荐答案
的base64
后输出10个字节,头
获得足够的投入和退出。当前的尝试,以输出多个字节,它将接收too.For同样的原因,<$ 并因此出口C $ C>猫将退出反过来。
After base64
outputs 10 bytes, head
gets enough inputs and exits. When the former attempts to output more bytes, it will receive SIGPIPE signal and hence exit too。For the same reason, cat
will exit in turn.
这篇关于这是为什么管终止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!