What happens when a producer ignores SIGPIPE while using head/tail for pagination?
29.5K reputation · 20 Apr 2023, 03:53 UTC
When a producer writes to a pipe that is consumed by pagination utilities such as head or tail, the consumer exits after delivering the requested number of lines and closes its read end.
If the producer does not check for EPIPE or ignores SIGPIPE, it may continue writing until the kernel pipe buffer fills, after which further writes block or return EAGAIN. The amount of data that can accumulate depends on the pipe buffer size (/proc/sys/fs/pipe-max-size) and any locale‑dependent line counting that head/tail performs.
This interaction raises uncertainty about whether simple pipelines guarantee timely termination of upstream processes, especially in UTF‑8 environments where line counts may differ from byte counts.
What determines the point at which a producer blocking on a full pipe is relieved? How does the pipe buffer size interact with the pagination limit to affect latency? Does setting LC_ALL=C eliminate variability in line‑counting for multibyte streams?