A question about read() system call!!

Leslie Mikesell les at chinet.chi.il.us
Thu May 23 07:58:20 AEST 1991


In article <28398698.26968 at maccs.dcss.mcmaster.ca> ashraf at maccs.dcss.mcmaster.ca (Ashraf Mahmoud) writes:

>  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? 

If you really want to do it that way you can use fcntl() to set the
O_NDELAY flag.  However, unless you are very careful to limit the
speed at which you loop through the read() requests you are likely
to swamp the machine with hundreds of system calls per second.  Sometimes
there are better ways to design a program - sometimes a 1 second
sleep in the loop will keep everybody happy.

Les Mikesell
  les at chinet.chi.il.us



More information about the Comp.unix.questions mailing list