0

Say I need to run a UNIX command-line program on some big file. If I want to see a bit of the output, I can pipe the output to head:

$ cat big_file.txt | head

For cat and many similar programs, this command runs extremely fast. Since only the first few lines are needed, program execution stops as soon as the requirement on the other end of the pipe is satisfied. So we all know and love this kind of pipe command for quickly exploring what's in a file or what kind of output a program will write for us.

How does this work at the code level? Does some kind of signal get sent to cat telling it that its output isn't needed anymore, and it can stop running now?

Paul
  • 3,321
  • 1
  • 33
  • 42
  • 1
    This unix.stackexchange answer explains it: [How does a pipeline know when to stop](http://unix.stackexchange.com/questions/268344/how-does-a-pipeline-knows-when-to-stop) – Mark Plotnick Nov 16 '16 at 20:31
  • This Q is not about programming as defined for StackOverflow. It **may** be more appropriate on the S.E. related site http://unix.stackexchange.com (Unix & Linux). Use the `flag` link at the bottom of your Q and ask the moderator to move it. Please don't post the same Q on 2 different sites. Please read http://stackoverflow.com/help/how-to-ask http://stackoverflow.com/help/dont-ask and http://stackoverflow.com/help/mcve before posting more Qs here. Good luck. – shellter Nov 16 '16 at 21:07

0 Answers0