Re: Reading FIFOs one character at a time

From: JQ (foo_at_bar.com)
Date: 08/31/04


Date: Mon, 30 Aug 2004 20:21:03 -0700

Peter Ammon wrote:
> I would like to write a program to read a FIFO (named pipe) one
> character per invocation. When I attempt to read the first character,
> the writing process finishes its write and terminates, and the first
> character is successfully read. However, the remaining data is lost.

Depending on the OS, a named pipe like this has an internal kernel
buffer. 512 bytes, 4096 bytes, and 32768 bytes I've seen. The OS will
also signal the writer once the reader terminates and thus will bit
bucket the remaining data left in the FIFO.

You've got two problems here, one is the indeterminate FIFO kernel
buffer and the other other is signals between the two processes. I
would suggest you use a message queue a la SysV IPC or some like to
accomplish what you want.

-- 
JQ


Relevant Pages

  • Request for comments - kgets()
    ... macro and a function-like macro macros below) ... pointers, dereferencing pointers, pointer arithmetic, and how (at ... character by character I can discuss a conceptual model of the ... FIFO Model - A block of memory having two pointers. ...
    (comp.lang.c)
  • Re: fork process to handle fifo input
    ... > work on the input of the named pipe. ... The current process's pid is available in $$: ... > process in order to collect to child processes before quiting. ... > collect data from syslog through the fifo as they should. ...
    (comp.lang.perl.misc)
  • Re: reading on serial port slow...
    ... FIFO has some characters waiting but no new ones have arrived ... IIRC "a while" is a few character times. ... the port to signal an interrupt after each character. ...
    (comp.os.linux.development.system)
  • Re: Are write() calls guaranteed atomic?
    ... > writing the data have no knowledge of the FIFO, ... If you cannot modify the clients, try changing your server to create a ... Unix domain socket instead of a named pipe (the clients shouldn't see ...
    (freebsd-hackers)
  • Re: 25 microseconds?
    ... Draining the serial FIFO in the ISR is by better ... than sipping one character at a time since each character in the FIFO is ... > Both ISR and DPC execution can kill performance. ... > ISR - 10 microseconds ...
    (microsoft.public.development.device.drivers)