Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我需要在某个大文件上运行 UNIX 命令行程序。如果我想查看一些输出,可以将输出通过管道传输到head:
head
$ cat big_file.txt | head
对于cat和许多类似的程序,这个命令运行得非常快。由于只需要前几行,因此一旦满足管道另一端的要求,程序执行就会停止。所以我们都知道并喜欢这种管道命令,用于快速探索文件中的内容或程序将为我们编写的输出类型。
cat
这在代码级别如何工作?是否会发送某种信号来cat告诉它不再需要它的输出,并且它现在可以停止运行?