📄 p3
字号:
.s15. Processes and images.esAn.ft Iimage.ftis a computer execution environment.It includes a core image,general register values,status of open files,current directory and the like.An image is the current state of a pseudo-computer..pgA.ft Iprocess.ftis the execution of an image.While the processor is executing on behalf of a process,the image must reside in core;during the execution of other processes it remains in coreunless the appearance of an active, higher-priorityprocessforces it to be swapped out to the fixed-head disk..pgThe user-core part of an image is divided into three logical segments.The program text segment begins at location 0 in the virtual address space.During execution, this segment is write-protectedand a single copy of it is shared amongall processes executing the same program.At the first 8K byte boundary above the program text segment in thevirtual address space begins a non-shared, writable data segment,the size of which may be extended by a system call.Starting at the highestaddress in the virtual address space is a stack segment,which automatically grows downwardas the hardware's stack pointer fluctuates..s25.1 Processes.esExcept while \*sUNIX\*n is bootstrapping itself into operation, a newprocess can come into existence onlyby use of the \fIfork\fR system call:.dcprocessid = fork\|(\|label\|)\|.ecWhen \fIfork\fR is executed by a process, itsplits into two independently executing processes.The two processes have independentcopies of the original core image,and share any open files.The new processes differ only in that one is consideredthe parent process:in the parent,control returns directly from the \fIfork\fR,while in the child, control is passedto location.ft Ilabel..ft RThe \fIprocessid\fR returned by the \fIfork\fR call is the identificationof the other process..pgBecause the return points in the parent and child processare not the same, each image existing after a\fIfork\fR may determine whether it is the parent or child process..s25.2 Pipes.esProcesses may communicatewith related processes using the same system.ft Iread.ftand.ft Iwrite.ftcalls that are used for file system I/O.The call.dcfilep = pipe\|(\|\|)\|.ecreturns a file descriptor \fIfilep\fR andcreates an inter-process channel called a \fIpipe\fR.This channel, like other open files, is passed from parent to child process inthe image by the \fIfork\fR call.A \fIread\fR using a pipe file descriptorwaits until another process writes using thefile descriptor for the same pipe.At this point, data are passed between the images of thetwo processes.Neither process need know that a pipe,rather than an ordinary file,is involved..pgAlthoughinter-process communicationvia pipes is a quite valuable tool(see \(sc6.2),it is not a completely generalmechanism,since the pipe must be set up by a common ancestorof the processes involved..s25.3 Execution of programs.esAnother major system primitiveis invoked by.dcexecute\|(\|file, arg\*t\d1\u\*n, arg\*t\d2\u\*n, .\|.\|. , arg\*t\dn\u\*n\|)\|.ecwhich requests the system to read in and execute the programnamed by \fIfile\fR, passing it string arguments.ft Iarg\v'.3'\*t1\*n\v'-.3'\|, arg\v'.3'\*t2\*n\v'-.3'\|, .\|.\|.\|\|, arg\v'.3'\*tn\*n\v'-.3'..ft RAll the code and data in the process using \fIexecute\fRis replaced from the \fIfile\fR,butopen files, current directory, andinter-process relationships are unaltered.Only if the call fails, for examplebecause \fIfile\fR could not be found or becauseits execute-permission bit was not set, does a returntake place from the \fIexecute\fRprimitive;it resembles a ``jump'' machine instructionrather than a subroutine call..s25.4 Process synchronization.esAnother process control system call.dcprocessid = wait\|(\|\|)\|.eccauses its caller to suspendexecution until one of its children has completed execution.Then \fIwait\fR returns the \fIprocessid\fR of the terminated process.An error return is taken if the calling process has nodescendants.Certain status from the child processis also available..s25.5 Termination.esLastly,.dcexit\|(\|status\|)\|.ecterminates a process,destroys its image,closes its open files,and generally obliterates it.When the parent is notified throughthe \fIwait\fR primitive,the indicated \fIstatus\fR is availableto the parent.Processes may also terminate as a result ofvarious illegal actions or user-generated signals(\(sc7 below).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -