I created a named pipe for another process for recording and I want to check that another process is started correctly, but does not know its PID. Context launches the command on the screen , making sure that the command is run correctly. I was hoping this might work:
mkfifo /tmp/foo echo hello > /tmp/foo & lsof /tmp/foo
Unfortunately, lsof
does not report echo
. inotifywait
may be another option, but it is not always installed, and I really want to poll only once, and not block until some event.
Is there a way to check if a named pipe is open for writing? In general, is it open?
UPDATE:
Once both ends are connected, lsof
works. This actually solves my problem, but for the sake of the question, I would be interested to know if it is possible to detect the initial redirect to the named pipe without reading.
> mkfifo /tmp/foo > yes > /tmp/foo & > lsof /tmp/foo > cat /tmp/foo > /dev/null & > lsof /tmp/foo COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME yes 16915 user 1w FIFO 8,18 0t0 16660270 /tmp/foo cat 16950 user 3r FIFO 8,18 0t0 16660270 /tmp/foo
source share