basic C question

Henry Spencer henry-lqW1N6Cllo0sV2N9l4h3zg at public.gmane.org
Mon Jul 12 21:23:23 UTC 2004


On Mon, 12 Jul 2004 fcsoft-3Emkkp+1Olsmp8TqCH86vg at public.gmane.org wrote:
> Once again if process A (the reader) creates the named pipe and process B 
> (the writer) opens a file descriptor to that pipe there appears to be no way 
> to detect that process A (the reader) has vanished.    ie. the write() will 
> always succeed.

It shouldn't; normally, the writing program will get blown away by a SIGPIPE
signal in that case.

However, you have to be careful about some details.  Notably, the writing
program must open it for writing *ONLY*.  If it opens it for both read and
write, then the fifo *is* open for reading even with no other process
involved, and so there's nothing wrong with doing a write() to it.

(It is actually possible, although rarely sensible, for the same program
to both read and write a fifo.)

Similarly, if any of the programs involved is using fork() and suchlike,
remember that fork() duplicates all file descriptors, so some uninvolved
process may still have a copy of that file descriptor.  (This is a classic
mistake in using regular pipes.)

                                                          Henry Spencer
                                                       henry-lqW1N6Cllo0sV2N9l4h3zg at public.gmane.org


--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list