A question about read() system call!!

Tom Armistead toma at swsrv1.cirr.com
Thu May 23 13:14:42 AEST 1991


In article <28398698.26968 at maccs.dcss.mcmaster.ca> ashraf at maccs.dcss.mcmaster.ca (Ashraf Mahmoud) writes:
>
>Hello Every Body,
>
>  I wonder if I can get help regarding the unix system call "read()".
>When a program executes this system call to read from an empty pipeline,  
>shouldn't it return zero ( nothing is read ) and passes control to the next 
>statement? I think it remains stuck waiting for something to be put it the 
>pipeline. How can I overcome this behaviour? That is making it pass control 
>to next statement even if pipeline is empty. I would appreciate responses.
>
>Ashraf   
>McMaster U.
>   

You need to use the O_NDELAY flags for open, e.g.

	open( "FILE", O_RDONLY|O_NDELAY )

This the 'non-blocking' I/O flag.  When you open a pipe in normal mode for
read and no other process has it opened for write, the open() will hang
(or if you try to open it for write and no one has it open for read).

With the O_NDELAY set, the open will fail (with -1) and errno will be set to
?(I think)? ENXIO.

Tom
-- 
Tom Armistead - Software Services - 2918 Dukeswood Dr. - Garland, Tx  75040
===========================================================================
toma at swsrv1.cirr.com                {egsner,letni,ozdaltx,void}!swsrv1!toma



More information about the Comp.unix.questions mailing list