ELSEIF
Your brief EB
378 stories from 115 feeds 431 clusters Refreshed 12 minutes ago next pull 00:22

TECH Signal 400

Piped processes reclaim terminal input by opening /dev/tty

A Unix process whose stdin is connected to a pipe can still read keyboard input by opening /dev/tty, which resolves to its controlling terminal independently of fd 0.

WHY IT MATTERS

Tools like less and fzf already use this technique to combine piped data with interactive input, but the mechanism is not widely understood; knowing it enables writing pipeline stages that accept terminal interaction while processing piped data.

Written by elseif from the cluster below · every claim links back to a source

The three things worth knowing

01

A process can infer its position in a pipeline by checking whether its stdin and stdout are terminals, eliminating the need for explicit stage numbering.

02

Downstream pipeline stages drain their stdin pipe, which blocks until the upstream process exits and closes the pipe, providing natural coordination without a separate signal.

03

Opening /dev/tty creates a new file descriptor to the controlling terminal, letting a piped process read keyboard input even when fd 0 is connected to a pipe.

THE CLUSTER

Same story, 1 feed.

ORDERED BY FIRST SEEN
nishantjosh.dev via Lobsters Reclaim the terminal Open ↗