When I echo
something to a named pipe made with mkfifo
, it hangs if no process is reading from that pipe. How can I prevent that, i.e., stop that from hanging?
And by the way, why is that hanging echo
process not listed in ps -e
or pstree
?
When I echo
something to a named pipe made with mkfifo
, it hangs if no process is reading from that pipe. How can I prevent that, i.e., stop that from hanging?
And by the way, why is that hanging echo
process not listed in ps -e
or pstree
?
It's not totally clear what your desired end result is from the question, so I will assume that your desire is to continue the program, but still have the write occur when possible. In that case, just background the operation:
echo foo > fifo &
As for why echo
is not listed in the process table, it's because echo
is a shell builtin.
echo
processes lying around. (Unlike in OP's original example, they will be separate processes since they're backgrounded.) Instead some mechanism is needed to immediately produce a failure when no reader is present. – R.. GitHub STOP HELPING ICE May 12 '14 at 13:33exec 3<fifo
). – R.. GitHub STOP HELPING ICE May 12 '14 at 14:34sleep
, for example. – jojman May 12 '14 at 14:48timeout
from GNU coreutils, orcratimeout
, orSIGALRM
. I would not suggest writing your own timeout logic. I would also suggest clarifying your question so your intent is more obvious to readers -- at least to me, it reads as a desire not to block rather than a desire not to write at all. – Chris Down May 12 '14 at 15:21