named pipes and O_RDWR

Oliver Laumann net at opal.cs.tu-berlin.de
Fri May 17 19:40:39 AEST 1991


Is it allowed to open(2) a named pipe (FIFO) with O_RDWR?

The X/Open Portability Guide explicitly says that in this case the
result of the call to open() is undefined.  On the other hand, P1003.1
and the manual pages on several UNIX versions do not explicitly forbid
this.

I have noticed that under SunOS, when a process opens several FIFOs
with O_RDWR and then writes a single byte into each of these in turn,
the 12th call to write() blocks.  It blocks even if I set the respective
file descriptors to non-blocking.

This doesn't happen under Ultrix 4.0.  I currently don't have access to
other systems that support named pipes, so I can't check it there.

Here is a small test program that demonstrates the `blocking write
syndrome'.  Before you run it, you have to mknod(8) 14 FIFOs named
0, 1, 2, etc. in the current directory.

#include <fcntl.h>

#define N 15

main () {
    int i, f[N];
    char buf[10];

    for (i = 0; i < N; i++) {
	sprintf (buf, "%d", i);
	if ((f[i] = open (buf, O_RDWR, 0)) == -1) {
	    perror (buf); return;
	}
    }
    for (i = 0; i < N; i++)
	printf ("%d: %d\n", i, write (f[i], buf, 1));
}

Regards,
--
Oliver Laumann    net at tub.cs.tu-berlin.de  net at tub.UUCP  ol at gnu.ai.mit.edu



More information about the Comp.unix.questions mailing list