Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!spool.mu.edu!uunet!convex!egsner!swsrv1!toma From: toma@swsrv1.cirr.com (Tom Armistead) Newsgroups: comp.unix.questions Subject: Re: A question about read() system call!! Message-ID: <1991May23.031442.25522@swsrv1.cirr.com> Date: 23 May 91 03:14:42 GMT Article-I.D.: swsrv1.1991May23.031442.25522 References: <28398698.26968@maccs.dcss.mcmaster.ca> Organization: Software Services: Garland, Tx Lines: 31 In article <28398698.26968@maccs.dcss.mcmaster.ca> ashraf@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@swsrv1.cirr.com {egsner,letni,ozdaltx,void}!swsrv1!toma