home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / std_unix / volume.22 / text0053.txt < prev    next >
Encoding:
Text File  |  1991-03-06  |  3.2 KB  |  68 lines

  1. Submitted-by: guido@cwi.nl (Guido van Rossum)
  2.  
  3. peter@ficc.ferranti.com (Peter da Silva) writes:
  4.  
  5. >Yes, fork() is a cleaner method of creating new processes. Yes, it takes
  6. >a fairly complex calling sequence to get spawn() to have anything like
  7. >the functionality of fork()...exec(). But I think it'd be worthwhile to
  8. >let a little heresy in in exchange for making POSIX more palatable to
  9. >folks in poorer environments.
  10.  
  11. I know of precedents even in OS'es that support fork(): Amoeba and
  12. Topaz support a variant of what you call spawn().  (Note that the
  13. spawn() functions found in Microsoft C for MS-DOS emulate either just
  14. exec() or fork()+exec()+wait(), which is much less powerful, but
  15. all that MS-DOS can support (last time I looked).)
  16.  
  17. Amoeba's UNIX emulation supports fork(), but since Amoeba has no virtual
  18. memory (yet), it is fairly expensive.  An alternative function is
  19. provided, "newproc()", which creates a child process running a
  20. different program (and, because it is Amoeba, also running on a
  21. different processor, in the average case) just like fork()+exec() would
  22. do, only much cheaper since the parent's address space never gets
  23. copied.
  24.  
  25. Amoeba's newproc() lets you change the two perhaps most important
  26. bits of "kernel state" that programs fiddle between fork() and exec():
  27. the set of signals to be ignored and the set of open file descriptors.
  28. The interface lets you specify a bitmask of signals that are to be
  29. ignored in the child (or -1 to inherit the parent's ignored signals)
  30. and an array of file descriptors which provides a mapping between file
  31. descriptors in the parent and in the child (also with an option to
  32. inherit all file descriptors from the parent).
  33.  
  34. Amoeba's library functions popen() and system() have been changed to
  35. use newproc(), and the shell uses newproc() for most simple program
  36. invocations (environment manipulations and a few other things make it
  37. fall back on fork()).  The performance gain was well worth the hacking.
  38.  
  39. The newproc() interface could also be implemented on UNIX using
  40. [v]fork() and exec(), although extreme cases of file descriptor
  41. permutations could fail if not enough spare file descriptors were
  42. available.
  43.  
  44. The Topaz operating system (an Ultrix clone for Firefly multiprocessors
  45. developed at DEC's System Research Centre in Palo Alto) has a similar
  46. but more complete feature in its Modula-2+ (and now Modula-3?) version
  47. of the OS interface, not because Topaz doesn't have virtual memory (it
  48. does), but because the average Modula-2+ binary is several megabytes.
  49.  
  50. In Topaz, you create a descriptor for the new process, which represents
  51. its relevant kernel state.  The descriptor is initialized to inherit
  52. all state from the parent, and you can call library functions that
  53. modify various parts of the descriptor; this is the equivalent of what
  54. you would do between fork() and exec() in real UNIX.  Finally you make
  55. a system call that presents the descriptor to the kernel for creation.
  56. Yes, it's a bit more tedious, but it has all the required
  57. functionality, unlike (it seems to me) the proposed qfork() with its
  58. not-well-understood restrictions on modifying memory.
  59.  
  60. --Guido
  61.  
  62. --
  63. Guido van Rossum, CWI, Amsterdam <guido@cwi.nl>
  64. "Well I'm a plumber.  I can't act."
  65.  
  66. Volume-Number: Volume 22, Number 55
  67.  
  68.