home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / programm / 3978 < prev    next >
Encoding:
Text File  |  1992-07-28  |  1.8 KB  |  46 lines

  1. Newsgroups: comp.unix.programmer
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!uchinews!machine!chinet!les
  3. From: les@chinet.chi.il.us (Leslie Mikesell)
  4. Subject: Re: Named pipes
  5. Message-ID: <1992Jul28.194627.6230@chinet.chi.il.us>
  6. Organization: Chinet - Public Access UNIX
  7. References: <1992Jul26.165838.1278@news.eng.convex.com> <92033@bu.edu> <1992Jul27.221133.27847@mintaka.lcs.mit.edu>
  8. Date: Tue, 28 Jul 1992 19:46:27 GMT
  9. Lines: 35
  10.  
  11. In article <1992Jul27.221133.27847@mintaka.lcs.mit.edu> mycroft@hal.gnu.ai.mit.edu (Charles Hannum) writes:
  12. >
  13. >> mknod testpipe p
  14. >> cat testpipe &
  15. >> ls > testpipe
  16. >> The "cat" process ends after the ls is sent to the screen.
  17.  
  18. >This is the way named pipes have worked since The Dawn of Time.  If you
  19. >want to have multiple processes write to the pipe, you need the reader
  20. >to reopen it.  In the shell, you could do something like this:
  21. >(while :;do cat testpipe;done)&
  22.  
  23. Cat just happens to be written to exit when it hits EOF.  So, either
  24. prevent it from seeing EOF by holding the write side open with an
  25. unused fd:
  26.   cat testpipe 4>testpipe &
  27. or use a process that doesn't exit at EOF.  Just be sure it sleeps
  28. a while between reads when there is no input.  A shell script that
  29. periodically reads a control fifo makes a handy server:
  30. do
  31.  read A B
  32.  ..process control command (if any) ..
  33.  ..do some work...
  34. done < fifo
  35.  
  36. You just have to start it in the background and throw it a real or
  37. dummy command command to unblock its open on the fifo, then you
  38. can "echo command argument > fifo"  manually or from other programs
  39. to control it.  (Try that with sockets...).  If you want it to
  40. wait for each command, open for write also ( done <fifo 4>fifo) 
  41. otherwise the reads are non-blocking after the fifo has been
  42. opened and closed by a writer.
  43.  
  44. Les Mikesell
  45.   les@chinet.chi.il.us
  46.