home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V6 / usr / doc / unix / p3 < prev    next >
Encoding:
Text File  |  1975-06-26  |  4.4 KB  |  163 lines

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