[LCP]read error

Hemant Mohan hemantm at pune.tcs.co.in
Tue Apr 23 18:47:05 UTC 2002


I am writing a program whereby I am opening a FIFO for reading. However the 
read is getting blocked though another process has already written to the 
FIFO and no other process is accesiing this FIFO.
the program is something like:

Process A
main()
{
    int fd;
    fd=open(FIFO, RD_ONLY );
    read(fd, ....)
}

Process B
main()
{
    mkfifo(FIFO, 0664);
    fd =open(FIFO, WR_ONLY);
    write(fd, ...);
    printf("data written to fifo\n");
}

Process B is run before process A, and the printf statement is desiplayed on 
the screen.
But I find that inspite of this process B is blocked on the read as if there 
is no data in the FIFO.

However if in process B, the open is done in non blocking mode 
fd = open(FIFO, RD_ONLY | O_NONBOCK)
then it doesn't block on read, but read returns a negative value and the 
errorno is set, with the message "Resource temporarily unavailable".

My question is that why does the read block initially, when there is some 
data for it to read. Under what conditions does the read normally block.


Thanks,
Hemant Mohan




More information about the linuxCprogramming mailing list