How can I make writes to named pipe block if the reader closes, and vice versa?
0
votes
1
answer
88
views
Right now if I write to a name pipe and then close the reader, the writer gets a SIGPIPE and then exits. For example,
$ mkfifo pipe
$ cat pipe & # read from the pipe in the background
$ cat > pipe # write to the pipe
line1
line2
...
If I then stop the reader process, the writer process dies because of the SIGPIPE the reader process sent when stopping.
I don't want this to happen. If the writer tries writing to the pipe *before* a reader appears, the writer blocks and waits for a reader. I want behavior like this. If the reader closes the pipe, the writer should block and wait for a new reader.
Likewise, if I stop the writer process, the reader process closes because it sees an EOF (or rather, a 0 byte read). I would also like for it to block until a new writer appears, instead.
Does cat
have a flag for doing this? If not, this is is probably a pretty simple C program.
Asked by Joseph Camacho
(109 rep)
Jan 30, 2025, 07:00 PM
Last activity: Jan 30, 2025, 09:21 PM
Last activity: Jan 30, 2025, 09:21 PM