Sunday, December 3, 2023

How to identify process is listening to FIFO (Handle brocken pipe issues)

 In my previous post about named pipes, I mentioned that, "there has to be a reading process "attached" for the other side of the pipe. If you try to open pipe for writing and there is no reading process, open will hang waiting for it"

But there can be issues if reading process is killed/ternminated after attching to FIFO. In that case there will  not be any listner on the other end and writing process would give "Broken pipe" error.

In that case you could use command lsof


e.g. lsof /tmp/myfifo 
Output: 
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME 
wr 64769 isurusa 3w FIFO 202,3 0t0 67668074 /tmp/myfifo 
rd 64781 isurusa 3r FIFO 202,3 0t0 67668074 /tmp/myfifo 

Obove output can be processed and make sure there is a propper listner attched to FIFO.

Below is some C++ code snipet for that.


No comments:

Post a Comment

Optimize you working enviorenment : Single command to create & move to a directory in linux (C Shell, Bash)

Usually move to a directory just after creating is bit of a anxious task specially if the directory name is too long. mkdir long-name-of...