Annotation of 43BSDReno/share/doc/ps2/01.cacm/p3, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.