[LCP]read error
Andrew Weaver
Andrew.Weaver at tecnomen.fi
Thu May 2 22:24:05 UTC 2002
Does process B terminate after the write?
> -----Original Message-----
> From: Hemant Mohan [SMTP:hemantm at pune.tcs.co.in]
> Sent: Tuesday, April 23, 2002 11:46 AM
> To: linuxcprogramming at lists.linux.org.au
> Subject: [LCP]read error
>
> 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
>
> _______________________________________________
> This is the Linux C Programming List
> : http://lists.linux.org.au/listinfo/linuxcprogramming List
More information about the linuxCprogramming
mailing list