Sysv pipes/FIFO's & blocking

Leslie Mikesell les at chinet.chi.il.us
Sat Aug 26 04:25:40 AEST 1989


In article <9348 at chinet.chi.il.us> les at chinet.chi.il.us (Leslie Mikesell) writes:
>What is supposed to happen under sysV if a pipe or FIFO contains
>3 characters and a read() requests 4 characters?  What about fread()?
>Is it documented anywhere?


I've received some mail replies that assumed that the writer was finished
and had closed the writing end of the pipe, in which case both read()
and fread() return the 3 available characters.  I wanted to know about
the case where the reader catches up, but the writer isn't finished.

On SysVr3.2 (AT&T 6386), read() will return the 3 available characters,
fread() will wait until 4 characters are available or EOF.

This surprised me a little:
-----------------
#/bin/sh
READ=500
while :
do
   echo "1" 
done |
while :
do
   dd bs=$READ count=1 of=/dev/null
done
-------------------
It gives a mixture of:
  1+0 records in
  1+0 records out
and
  0+1 records in
  0+1 records out
with the latter form increasing with the size of READ.  Why?

Les Mikesell



More information about the Comp.unix.questions mailing list