home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / unix / question / 14775 < prev    next >
Encoding:
Internet Message Format  |  1992-12-17  |  1.8 KB

  1. Path: sparky!uunet!think.com!barmar
  2. From: barmar@think.com (Barry Margolin)
  3. Newsgroups: comp.unix.questions
  4. Subject: Re: cat a > a , getting it straight
  5. Date: 17 Dec 1992 20:18:23 GMT
  6. Organization: Thinking Machines Corporation, Cambridge MA, USA
  7. Lines: 34
  8. Message-ID: <1gqnafINNn8e@early-bird.think.com>
  9. References: <1992Dec17.020805.28043@news.acns.nwu.edu> <1gp7lsINNlok@early-bird.think.com> <1992Dec17.074018.3226@news.acns.nwu.edu>
  10. NNTP-Posting-Host: telecaster.think.com
  11.  
  12. In article <1992Dec17.074018.3226@news.acns.nwu.edu> navarra@casbah.acns.nwu.edu (John Navarra) writes:
  13. >[riemann:62] ~/tmp -> cat a | cat > a
  14. >[riemann:63] ~/tmp -> cat a
  15. >file a
  16. >
  17. >But, this output is not predictable. Sometimes, a was clobbered several
  18. >times in a row. Sometimes, a was preserved several times in a row. Once,
  19. >I even got this:
  20.  
  21. The shell runs both parts of a pipeline concurrently.  Sometimes the "cat
  22. a" manages to run to completion before "cat > a" gets started, so it can
  23. read the file before it gets clobbered.  Other times the "cat > a" starts
  24. first, so "cat a" sees an empty input file.
  25.  
  26. >[casbah:58] ~/tmp -> cat a | cat > a
  27. >cat: write error: Bad address
  28.  
  29. In this case, "cat > a" started in the middle of "cat a".  On Suns, the cat
  30. command works by mmap()ing the input file if it's an ordinary file, and
  31. then using that memory as the output buffer in a write() call.  What
  32. happened here is that the file was truncated between the mmap() and the
  33. write(), so the write() tried to access memory that was no longer
  34. allocated.
  35.  
  36. >Somebody is not doing their job right. I couldn't reproduce this on non-Sun
  37. >machines though.
  38.  
  39. Depends on what you consider "right".  You're not supposed to be able to do
  40. this, so anything that happens is right.
  41. -- 
  42. Barry Margolin
  43. System Manager, Thinking Machines Corp.
  44.  
  45. barmar@think.com          {uunet,harvard}!think!barmar
  46.