这是为什么管终止? [英] Why is this pipe terminated?

查看:128
本文介绍了这是为什么管终止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个管道命令随机产生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同样的原因,<$ SIGPIPE信号并因此出口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.

这篇关于这是为什么管终止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆