home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / question / 9590 < prev    next >
Encoding:
Text File  |  1992-07-30  |  2.4 KB  |  70 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!stanford.edu!leland.Stanford.EDU!drizzle.Stanford.EDU!eillihca
  3. From: eillihca@drizzle.Stanford.EDU (Achille Hui)
  4. Subject: Re: question on "&"
  5. Message-ID: <eillihca.712516811@drizzle.Stanford.EDU>
  6. Sender: news@leland.Stanford.EDU (Mr News)
  7. Organization: DSO, Stanford University
  8. References: <1992Jul28.073403.3530@u.washington.edu>
  9. Date: 30 Jul 92 17:20:11 GMT
  10. Lines: 58
  11.  
  12. sue@byron.u.washington.edu (Shu-Chen Eclipse) writes:
  13.  
  14. >I'm a crass beginnier in unix: I know "&" means something like start a 
  15. >process running in the background, I guess, something like vms's "run/detached";while browsing through some scripts, I saw a line something like
  16. >(/../.../some file name &)&.
  17.  
  18. >  what does the 2 "&" mean?
  19. >thanx in advance,
  20. >sue@byron.u.washington.edu
  21.  
  22. The 2nd "&" also means running the process in background. Consider the
  23. following shell script:
  24.  
  25. #!/bin/sh
  26. w & 
  27. exec sleep 100
  28.  
  29. Run this in background and do a "ps", you will discover a process
  30. marked as <exiting> or something like that. This is the "Zombie" left
  31. by the process "w". The kernel has release all the resources attached
  32. to this process except a process slot to hold its exit value. If its
  33. parent doesn't wait for it, it will be there until its parent die.
  34. Imagine you have a program that spawn off infinity many background
  35. sub processes but doesn't wait for it. You will ultimately running
  36. out of process slots and can't start any new process.
  37.  
  38. A common trick to avoid such zombies in shell scripts is the 
  39. double fork you have noticed:
  40.  
  41. ( ProgramInBackground &)&
  42.  
  43. When the outer shell die, the parent ID of the ProgramInBackground no
  44. longer valid. The kernel replace this by 1, the process ID of the "init"
  45. process which is the ancestor of all other process. Since init will 
  46. take care of the exit value of ProgramInBackground when it exits, no
  47. process slot will be wasted.
  48.  
  49. By the way, your question is one of the few questions that is appropriate
  50. for this group. Don't be discouraged by other netters who don't know
  51. when "RTFM -- Read the F-word Manuals" is the appropriate answer of
  52. your question.
  53.  
  54. P.S:    If you really want to dig into detail of all this mess. look
  55.     at the manual pages about the system call of exec, fork, wait
  56.     and a very good reference of this stuff is Ch.2 of the book
  57.     UNIX Network programming  by W.Richard Stevens.
  58.  
  59. Hopefully this helps....
  60. -------------------------------------achille (eillihca@drizzle.stanford.edu)
  61. JAUU    -- Just Another UNIX User.    
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.