Re: How to do a blocking read() ?



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



Relevant Pages

  • Re: How to do a blocking read() ?
    ... If you use a pipe (perhaps a named pipe), ... There is also a Linux-specific solution using dnotify. ... But, if Linux specific, then since Linux 2.6.13, better is inotify -- ... mostly on portabilty requirements. ...
    (comp.os.linux.development.apps)
  • Re: Print to Email
    ... script to monitor the named pipe if there is something in it, ... off my server -- it seems the smtp conversation between sendmail ... packets of interest from my linux box. ... winbox mail sending endeavor, and am still poring over the results... ...
    (linux.redhat.misc)
  • Re: Registering for SIGPOLL signals from a named pipe
    ... A colleague has inherited rather a large lump of Solaris code which he is ... porting to Linux. ... events occur on a named pipe. ... There is a STREAMS package for Linux, ...
    (comp.os.linux.development.system)
  • Re: How to do a blocking read() ?
    ... The intention is that ... another process have a routine which will sit and wait for new data ... If you use a pipe (perhaps a named pipe), ... But, if Linux specific, then since Linux 2.6.13, better is inotify -- ...
    (comp.os.linux.development.apps)
  • [GIT PULL] inotify regresion in -rc8 causes boot hang/failure
    ... Linux 2.6.31-rc8 ... are available in the git repository at: ... Brian Rogers: ... inotify: do not send a block of zeros when no pathname is available ...
    (Linux-Kernel)