home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / os / os9 / 1244 < prev    next >
Encoding:
Text File  |  1992-09-15  |  2.4 KB  |  61 lines

  1. Newsgroups: comp.os.os9
  2. Path: sparky!uunet!europa.asd.contel.com!darwin.sura.net!haven.umd.edu!wam.umd.edu!ignatz
  3. From: ignatz@wam.umd.edu (Mark J. Sienkiewicz)
  4. Subject: Re: Deallocation of process descriptors.
  5. Message-ID: <1992Sep15.140540.13468@wam.umd.edu>
  6. Sender: usenet@wam.umd.edu (USENET News system)
  7. Nntp-Posting-Host: rac3.wam.umd.edu
  8. Organization: University of Maryland, College Park
  9. References: <1992Sep15.081851.10686@cs.nott.ac.uk>
  10. Date: Tue, 15 Sep 1992 14:05:40 GMT
  11. Lines: 48
  12.  
  13. In article <1992Sep15.081851.10686@cs.nott.ac.uk> pczip@mips.nott.ac.uk (Ivan Powis) writes:
  14. >so the parent does not do a 'wait' for the child. This all works, but leaves
  15. >behind a trail of 'dead' non deallocated process descriptors until some
  16. >indefinite time in the future when the parent process is killed off. How can
  17. >I force these unwanted descriptors to be deallocated when the child terminates?
  18.  
  19. This is the way it is supposed to work so you can find out exit statuses
  20. of your child processes.
  21.  
  22. >It seems this situation is analogous to a shell creating background processes
  23. >with the 'command &' facility. The shell doesn't leave a trail of dead
  24. >descriptors in its wake, so there must be some way to achieve the desired
  25. >effect.
  26.  
  27. This is because the shell does a wait every time you type a command that
  28. doesn't go into the background.  For example, if you type 'procs' to
  29. see what is there, your shell will do a wait and get the status codes
  30. from the dead background process _before_ procs finds them in the process
  31. table.
  32.  
  33. --
  34.  
  35. What you need to do is to orphan the child processes.  If the parent
  36. exits before the child, the child no longer has a parent and it's 
  37. process table entry will be deallocated when it dies.
  38.  
  39. To do this on OS9, you need a program that runs programs.  The simplest
  40. way to do this is:
  41.  
  42.     parent()
  43.     {
  44.     system("child &");
  45.     }
  46.  
  47. Note that system() will create a shell.  You tell the shell to run the
  48. program child _without_ waiting for it.  The shell then immediately
  49. terminates.  parent() ends up doing a wait() for a few ticks while the 
  50. shell sets things up, but as soon as the shell is done, parent() 
  51. _does_not_have_any_children_.  But there is an orphaned process
  52. hanging around running "child".  When child exits, there is no parent
  53. to report the exit status to, so it just goes away.
  54.  
  55. I do the equivalent of this, but I have a special program that I use
  56. instead of the shell.  It is just a call to os9fork() or os9exec() or
  57. something like that.
  58.  
  59. Mark S.
  60.  
  61.