UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2016-04-01 04:59 PM

useless79
Member
Registered: 2011-10-10
Posts: 30

cat is blocking in named pipe

Hi All,

I have written a program having two processes P1 and P2. P1 sends binary data from one end via a named pipe. P2 on the other end which receives the data is actually a shell script which
uses a cat cmd to named pipe which in turn sends to some other binary some thing like     cat  "/tmp/named_pipe"   >  bin          (in P2 shell script)
I see cat is blocked on named pipe even when the other end of the pipe ie P1 is done with sending binary data.  Can any one let me know how can I inform cat that other end is done
sending data hence unblock ??



           P1    -----------> named pipe  --------------->  P2 (shell script some thing like    cat  "/tmp/named_pipe"  > bin  )   






Thanks for the help in advance.

Offline

#2 2016-04-01 08:00 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,829
Website

Re: cat is blocking in named pipe

Have P1 close its file descriptor for the pipe...  That should signal EOF on the pipe for the reading cat...

Offline

#3 2016-04-01 08:25 PM

useless79
Member
Registered: 2011-10-10
Posts: 30

Re: cat is blocking in named pipe

yes i have done but no effect.  what i observed also when i simply cat a named pipe's file whose both ends are dead, cat hangs looks like it expect some data in file which is not availiable and will never be hence hangs infinitely.

Offline

#4 2016-04-02 03:30 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,829
Website

Re: cat is blocking in named pipe

If you start the cat after the close of the writer, then yes it'll wait around for another writer...  But, if you do the close while the cat is blocked waiting to read, that should signal EOF and terminate the cat...

Offline

Board footer

Powered by FluxBB