home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / lisp / lispnews / text0023.txt < prev    next >
Encoding:
Text File  |  1985-11-10  |  3.2 KB  |  92 lines

  1. There are now three new functions for dealing with processes:
  2.   *process
  3.   *process-send
  4.   *process-receive
  5.  
  6.  These functions are designed to replace the 'process' function, which, due
  7. to its nlambda'ness, was difficult to use.  All of the above functions
  8. are lambda's or lexpr's.
  9.  
  10.   See chapter 6 of the manual (its on-line) for the details of these
  11. functions.  This is a quick summary:
  12.  
  13.   (*process-send 'st_command)
  14.   tells the shell to run the command st_command concurrently, and returns
  15.   a write-only port.  Characters written to this port will appear at
  16.   the standard input of st_command.
  17.   example:
  18.      (setq p (*process-send "mail jkf"))
  19.      (print 'HiThere p)
  20.      (close p)
  21.  
  22.      
  23.   (*process-receive 'st_command)
  24.   tells the shell to run st_command concurrently, and returns a
  25.   read-only port.  Characters written to the standard output by
  26.   st_command will be available by reading from the given port.
  27.   Characters written on the standard error by st_command will
  28.   appear on lisp's the standard error (the terminal most likely).
  29.   example:
  30.     ; to see if foo is logged in:
  31.     (setq p (*process-receive "u"))
  32.     (do ((user (read p '**eof**) (read p '**eof**)))
  33.         ((eq '**eof** user) (print 'Not-Logged-In))
  34.     (cond ((eq 'foo user) (print 'Is-Logged-In))))
  35.     (close p)
  36.  
  37.  
  38.   (*process 'st_command ['g_readp ['g_writep]])
  39.   this is the general function which process, *process-send and
  40.   *process-receive call.  If called with one argument it
  41.   starts the new process and waits for it to end, e.g:
  42.   (*process (concat "vi " filename))
  43.   In this case *process return the exit code of the process.
  44.  
  45.   The g_readp and g_writep arguments, if given, tell *process to
  46.   run the process concurrently.  If g_read is non nil then
  47.   *process will return a port just like *process-receive.
  48.   If g_writep is non-nil, then *process will set up a pipe like
  49.   *process-send.
  50.   *process will return a list of the form
  51.     (readport writeport process-id)
  52.     where readport and writeport will only be a port if g_readp
  53.     or g_writep are non nil.
  54.  
  55.  
  56.  A little know fact about processes is that  a process, once started,
  57. cannot die and disappear until its parent asks about its status.
  58. Take the mail example given above:
  59.      (setq p (*process-send "mail jkf"))
  60.      (print 'HiThere p)
  61.      (close p)
  62. after the mail process finishes it work, it will attempt to die, returning
  63. an integer called the 'exit status'.  However until the lisp program
  64. asks about its status the mail process will remain in existence
  65. in a Zombie state, somewhere between life and death. ps will show this:
  66.  
  67.   PID TT STAT  TIME COMMAND
  68.  3876 p0 Z     0:01 <exiting>
  69.  
  70. A user is only allowed a small number of processes, so if you continue
  71. to generate processes and leave them around as Zombies, you will eventually
  72. run out of processes.  The way to let the Zombie die is to call
  73. the wait function, e.g.
  74.     -> (wait)
  75.     (3876 . 0)
  76.     -> 
  77. this says that process 3876 died with exit status 0.
  78.  
  79. Also, when you exit lisp the shell will clean up the Zombies.
  80.  
  81. If you start a  process with (*process "vi foo") then lisp will wait
  82. for it to complete before continuing, so you don't have to worry about
  83. Zombies.  You only have to worry if you run a process concurrently,
  84. such as when you use *process-send or *process-receive.
  85.  
  86.       
  87.        
  88.       
  89.  
  90.  
  91.  
  92.