Re: How to do a blocking read() ?
- From: Rainer Weikusat <rweikusat@xxxxxxxxxxx>
- Date: Wed, 30 May 2007 09:22:38 +0200
Michael Kerrisk <michael.kerrisk.nospam@xxxxxxx> writes:
On Mon, 28 May 2007 17:01:51 -0700, Paul Pluzhnikov
<ppluzhnikov-nsp@xxxxxxxxxxx> wrote:
Charles Sullivan <cwsulliv@xxxxxxxxxxxx> writes:
The situation is that I have a background process which sporadically
writes short bursts of data to a spool file. The intention is that
another process have a routine which will sit and wait for new data
to become available, then read it.
I thought a blocking read() could do this - am I mistaken?
Yes, you are.
If you use a pipe (perhaps a named pipe), then read will block
until the data is available.
But if you insist on an on-disk file, then read will never block;
and you'll have to loop doing sleep and fstat, until file size
changes.
There is also a Linux-specific solution using dnotify.
See "man fcntl", search for F_NOTIFY.
But, if Linux specific, then since Linux 2.6.13, better is inotify --
see the inotify(7) man page.
One would assume that 'Linux application development' is quite
linux-specific. Apart from that, if inotify is any 'better' depends
mostly on portabilty requirements.
.
- Follow-Ups:
- Re: How to do a blocking read() ?
- From: Michael Kerrisk
- Re: How to do a blocking read() ?
- References:
- How to do a blocking read() ?
- From: Charles Sullivan
- Re: How to do a blocking read() ?
- From: Paul Pluzhnikov
- Re: How to do a blocking read() ?
- From: Michael Kerrisk
- How to do a blocking read() ?
- Prev by Date: Re: Eclipse installation...
- Next by Date: Re: too many shared libraries
- Previous by thread: Re: How to do a blocking read() ?
- Next by thread: Re: How to do a blocking read() ?
- Index(es):
Relevant Pages
|