home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V7 / usr / doc / cacm / p3 < prev    next >
Encoding:
Text File  |  1979-01-10  |  4.3 KB  |  184 lines

  1. .SH
  2. V. PROCESSES AND IMAGES
  3. .PP
  4. An
  5. .IT image
  6. is a computer execution environment.
  7. It includes a memory image,
  8. general register values,
  9. status of open files,
  10. current directory and the like.
  11. An image is the current state of a pseudo-computer.
  12. .PP
  13. A
  14. .IT process
  15. is the execution of an image.
  16. While the processor is executing on behalf of a process,
  17. the image must reside in main memory;
  18. during the execution of other processes it remains in main memory
  19. unless the appearance of an active, higher-priority
  20. process
  21. forces it to be swapped out to the disk.
  22. .PP
  23. The user-memory part of an image is divided into three logical segments.
  24. The program text segment begins at location 0 in the virtual address space.
  25. During execution, this segment is write-protected
  26. and a single copy of it is shared among
  27. all processes executing the same program.
  28. At the first hardware protection byte boundary above the program text segment in the
  29. virtual address space begins a non-shared, writable data segment,
  30. the size of which may be extended by a system call.
  31. Starting at the highest
  32. address in the virtual address space is a stack segment,
  33. which automatically grows downward
  34. as the stack pointer fluctuates.
  35. .SH
  36. 5.1 Processes
  37. .PP
  38. Except while
  39. the system
  40. is bootstrapping itself into operation, a new
  41. process can come into existence only
  42. by use of the
  43. .UL fork
  44. system call:
  45. .P1
  46. processid = fork\|(\|\|)\|
  47. .P2
  48. When
  49. .UL fork
  50. is executed, the process
  51. splits into two independently executing processes.
  52. The two processes have independent
  53. copies of the original memory image,
  54. and share all open files.
  55. The new processes differ only in that one is considered
  56. the parent process:
  57. in the parent,
  58. the returned
  59. .UL processid
  60. actually identifies the child process
  61. and is never 0,
  62. while in the child,
  63. the returned value is always 0.
  64. .PP
  65. Because the values returned by
  66. .UL fork
  67. in the parent and child process are distinguishable,
  68. each process may determine whether
  69. it is the parent or child.
  70. .SH
  71. 5.2 Pipes
  72. .PP
  73. Processes may communicate
  74. with related processes using the same system
  75. .UL read
  76. and
  77. .UL write
  78. calls that are used for file-system I/O.
  79. The call:
  80. .P1
  81. filep = pipe\|(\|\|)\|
  82. .P2
  83. returns a file descriptor
  84. .UL filep
  85. and
  86. creates an inter-process channel called a
  87. .IT pipe .
  88. This channel, like other open files, is passed from parent to child process in
  89. the image by the
  90. .UL fork
  91. call.
  92. A
  93. .UL read
  94. using a pipe file descriptor
  95. waits until another process writes using the
  96. file descriptor for the same pipe.
  97. At this point, data are passed between the images of the
  98. two processes.
  99. Neither process need know that a pipe,
  100. rather than an ordinary file,
  101. is involved.
  102. .PP
  103. Although
  104. inter-process communication
  105. via pipes is a quite valuable tool
  106. (see Section 6.2),
  107. it is not a completely general
  108. mechanism,
  109. because the pipe must be set up by a common ancestor
  110. of the processes involved.
  111. .SH
  112. 5.3 Execution of programs
  113. .PP
  114. Another major system primitive
  115. is invoked by
  116. .P1
  117. execute\|(\|file, arg\*s\d1\u\*n, arg\*s\d2\u\*n, .\|.\|. , arg\*s\dn\u\*n\|)\|
  118. .P2
  119. which requests the system to read in and execute the program
  120. named by
  121. .UL file ,
  122. passing it string arguments
  123. .UL arg\v'.3'\*s1\*n\v'-.3'\| ,
  124. .UL arg\v'.3'\*s2\*n\v'-.3'\| ,
  125. .UL .\|.\|.\|\| ,
  126. .UL arg\v'.3'\*sn\*n\v'-.3' .
  127. All the code and data in the process invoking
  128. .UL execute
  129. is replaced from the
  130. .UL file ,
  131. but
  132. open files, current directory, and
  133. inter-process relationships are unaltered.
  134. Only if the call fails, for example
  135. because
  136. .UL file
  137. could not be found or because
  138. its execute-permission bit was not set, does a return
  139. take place from the
  140. .UL execute
  141. primitive;
  142. it resembles a ``jump'' machine instruction
  143. rather than a subroutine call.
  144. .SH
  145. 5.4 Process synchronization
  146. .PP
  147. Another process control system call:
  148. .P1
  149. processid = wait\|(\|status\|)\|
  150. .P2
  151. causes its caller to suspend
  152. execution until one of its children has completed execution.
  153. Then
  154. .UL wait
  155. returns the
  156. .UL processid
  157. of the terminated process.
  158. An error return is taken if the calling process has no
  159. descendants.
  160. Certain status from the child process
  161. is also available.
  162. .SH
  163. 5.5 Termination
  164. .PP
  165. Lastly:
  166. .P1
  167. exit\|(\|status\|)\|
  168. .P2
  169. terminates a process,
  170. destroys its image,
  171. closes its open files,
  172. and generally obliterates it.
  173. The parent is notified through
  174. the
  175. .UL wait
  176. primitive,
  177. and
  178. .UL status
  179. is made available
  180. to it.
  181. Processes may also terminate as a result of
  182. various illegal actions or user-generated signals
  183. (Section VII below).
  184.