comm '! sort file1' '! sort file2'

Eduardo Krell ekrell at ulysses.UUCP
Wed Oct 8 22:40:53 AEST 1986


I just implemented this feature on SVR3 by adding "seekable pipes". What I really
did was to port the /dev/fd hack from V8 and I also added a new file control
command to "block on eof".
  When a process opens a file for reading with this flag, an attempt to read() past
the end of file will block provided some other process is writing to that file.
When data is written to the file, the reader will awake and continue as normal.
Very similar to pipes.
  When you type (in ksh) "diff <(sort file1) <(sort file2)", the following happens

1) a file is created in /tmp. it is opened once for reading and once for writing.
an fcntl() is done to add the "block on eof" attribute. It is then unlink()ed.

2) A pipe is created to read from "sort file1". Say the reader file descriptor is 3.
The "<(sort file2)" argument is replaced by "/dev/fd/3". Same thing happens to the
second argument.

3) When diff opens /dev/fd/3, it will be actually reading from the pipe. seek()s
are ok since it is actually reading from a file in /tmp.

4) Since the file was unlink()ed, it will go away after both sort and diff finish.

-- 
    
    Eduardo Krell                   AT&T Bell Laboratories, Murray Hill

    {ihnp4,seismo,ucbvax}!ulysses!ekrell



More information about the Comp.unix.wizards mailing list