`pipe` forces write?

Keith Rohrer (rohrer@uiuc.edu)
Wed, 4 Dec 1996 04:11:21 -0600 (CST)

I've discovered that doing something like the following under csh or tcsh:
while (1)
set foo = `echo bar | cat`
it causes continuous disk activity even in the presence of gobs of free
pages (and without the while loop around it will still cause an immediate
write). the sh moral equivalent:
while true; do set foo = `echo bar | cat` ; done
doesn't cause the disk to churn...nor does it drive the CPU usage up beyond
about 15% (total for the loop and top), even once the disk becomes completely
idle. I see this on both my 486DX2-100 (kernel 2.1.13) or my 486DLC-40

Obviously, Berkeley csh and tcsh are being inefficent about backquoted tails
of pipes (get rid of the piping and the disk activity goes away), but I don't
think that the kernel should be insisting on doing a write to the device so
immediately. Also, the lack of CPU usage seems quite odd...

Are these fsync() calls in some shell code combined with a deliberate time-
wasting mechanism held secret in the depths of UN*X specs all these years,
or what?

Keith (this task fits in memory; it ought to act like it)