📄 p3
字号:
.SHV. PROCESSES AND IMAGES.PPAn.IT imageis a computer execution environment.It includes a memory image,general register values,status of open files,current directory and the like.An image is the current state of a pseudo-computer..PPA.IT processis the execution of an image.While the processor is executing on behalf of a process,the image must reside in main memory;during the execution of other processes it remains in main memoryunless the appearance of an active, higher-priorityprocessforces it to be swapped out to the disk..PPThe user-memory 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 hardware protection 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 stack pointer fluctuates..SH5.1 Processes.PPExcept whilethe systemis bootstrapping itself into operation, a newprocess can come into existence onlyby use of the.UL forksystem call:.P1processid = fork\|(\|\|)\|.P2When.UL forkis executed, the processsplits into two independently executing processes.The two processes have independentcopies of the original memory image,and share all open files.The new processes differ only in that one is consideredthe parent process:in the parent,the returned.UL processidactually identifies the child processand is never 0,while in the child,the returned value is always 0..PPBecause the values returned by.UL forkin the parent and child process are distinguishable,each process may determine whetherit is the parent or child..SH5.2 Pipes.PPProcesses may communicatewith related processes using the same system.UL readand.UL writecalls that are used for file-system I/O.The call:.P1filep = pipe\|(\|\|)\|.P2returns a file descriptor.UL filepandcreates an inter-process channel called a.IT pipe .This channel, like other open files, is passed from parent to child process inthe image by the.UL forkcall.A.UL readusing 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..PPAlthoughinter-process communicationvia pipes is a quite valuable tool(see Section 6.2),it is not a completely generalmechanism,because the pipe must be set up by a common ancestorof the processes involved..SH5.3 Execution of programs.PPAnother major system primitiveis invoked by.P1execute\|(\|file, arg\*s\d1\u\*n, arg\*s\d2\u\*n, .\|.\|. , arg\*s\dn\u\*n\|)\|.P2which requests the system to read in and execute the programnamed by.UL file ,passing it string arguments.UL arg\v'.3'\*s1\*n\v'-.3'\| ,.UL arg\v'.3'\*s2\*n\v'-.3'\| ,.UL .\|.\|.\|\| ,.UL arg\v'.3'\*sn\*n\v'-.3' .All the code and data in the process invoking.UL executeis replaced from the.UL file ,butopen files, current directory, andinter-process relationships are unaltered.Only if the call fails, for examplebecause.UL filecould not be found or becauseits execute-permission bit was not set, does a returntake place from the.UL executeprimitive;it resembles a ``jump'' machine instructionrather than a subroutine call..SH5.4 Process synchronization.PPAnother process control system call:.P1processid = wait\|(\|status\|)\|.P2causes its caller to suspendexecution until one of its children has completed execution.Then.UL waitreturns the.UL processidof the terminated process.An error return is taken if the calling process has nodescendants.Certain status from the child processis also available..SH5.5 Termination.PPLastly:.P1exit\|(\|status\|)\|.P2terminates a process,destroys its image,closes its open files,and generally obliterates it.The parent is notified throughthe.UL waitprimitive,and.UL statusis made availableto it.Processes may also terminate as a result ofvarious illegal actions or user-generated signals(Section VII below).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -