Shared file descriptors

John F. Haugh II jfh at rpp386.Dallas.TX.US
Wed May 31 11:29:55 AEST 1989


In article <1770 at taux01.UUCP> gil%taux01 at nsc.COM (Gil Shwed) writes:
>	main() {
>		char buf[8192];
>		int n;
>
>		fork();
>		while((n = read(0, buf, 8192)) > 0)
>			write(1, buf, n);
>		exit(0);
>	}
>	Then, run:
>
>		a.out < /vmunix > out
>
>	Now, run:
>		cmp /vmunix out
>
>	They should be the same, but...

No, they shouldn't.

You are assuming the read-write pair is atomic, which it isn't.  It
would be quite possible for either process to step in between a
read and write and copy another block.  A possible scenario is

proc 1:READ()  ... wait ...  WRITE()
proc 2:       READ() WRITE()

In this situation, input block 0 would be output block 1, and so
on.

I'll leave the more pathological cases to your imagination.  This
does not appear to contradict the claim that there is a bug, but
it does question your methods ...
-- 
John F. Haugh II                        +-Button of the Week Club:-------------
VoiceNet: (512) 832-8832   Data: -8835  | "AIX is a three letter word,
InterNet: jfh at rpp386.Cactus.Org         |  and it's BLUE."
UucpNet : <backbone>!bigtex!rpp386!jfh  +--------------------------------------



More information about the Comp.bugs.4bsd.ucb-fixes mailing list