[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: About problems with named pipes



On Sun, Nov 9, 2025 at 11:49 PM Thomas Schmitt <scdbackup@gmx.net> wrote:
> i think it is worth a mail thread to investigate the problem mentioned
> by Van Snyder in the course of thread "where does command output go".
> Van Snyder wrote:
> > my program opens MyFifo (created by mkfifo if it
> > doesn't already exist) for reading and then runs "zcat TheFile.gz | MyFifo"
> > If one of the files is big, instead of zcat blocking until my program
> > consumes more data, they both block.

What problems?
With a named pipe, it's (generally considered) an error to write it before
something has opened it for reading.  So, you open it for reading first,
And that then blocks at least until there's some data there to read, or EOF.
No reason to be executing or attempting to execute a named pipe.
$ mknod p p
$ < p > out cat &
[1] 18774
$ echo hello > p; wait; cat out
[1]+  Done                    cat < p > out
hello
$
This is generally how named pipes have behaved on *nix for about 45+ years.

And there's no reason to attempt to execute a named pipe.
But, well, if we do ...:
$ chmod u+x p
$ ./p > p.out &
[1] 19107
$ cat /usr/bin/date > p & wait
[2] 19162
-bash: ./p: Permission denied
[1]-  Exit 126                ./p > p.out
[2]+  Broken pipe             cat /usr/bin/date > p
$ ./p > p.out &
[1] 19249
$ cat /dev/null > p & wait
[2] 19259
-bash: ./p: Permission denied
[1]-  Exit 126                ./p > p.out
[2]+  Done                    cat /dev/null > p
$
Whether the named pipe gets data or EOF, looks like that then
unblocks the "read" (execution attempt), and that then fails with
Permission denied.
If we check more closely with strace(1) ... well, dash(1) (essentially
minimal POSIX shell)
immediately fails, whereas bash(1) fails once the pipe has data or EOF.
Either way, peeking bit more with strace(1) ...
execve("./p", ...) = -1 EACCES (Permission denied)
Either way, the kernel stubbornly and appropriately refuses to allow
execution of a named pipe.

So, at least as I see it, I'm not seeing any named pipe problems.
They seem to be working very much as designed and intended,
and as they generally have for 45+ years.


Reply to: