Vous êtes sur la page 1sur 2

c  



Every process under UNIX is created using the ? system call. UNIX pioneered
this concept of creating two nearly identical processes from one original process. The
original process is known as the parent process and the new process is the child
process. Figure 19.1 shows how three processes are related in this manner.
   
In Figure 19.1, the shell process ID Jlost its parent process, because it terminated.
All orphaned processes are inherited by the
 process, and its process ID is
always J Consequently, the shell's parent becomes process ID J When the J
command is typed in at the shell prompt, a ? and a are performed,
resulting in the process ID Jbeing created as a child process of the shell.
Conceptually, the ? call is like meeting a fork in the road. Initially there is one
process executing. Upon successful return from the ? function are two nearly
identical processes. The difference is that one has the child process ID returned from
? whereas the child process has the value returned instead.
The two processes share the following characteristics:
Process group ID
Current working directory
Root directory
bits
Real and effective user ID values
Real and effective group ID values
Set-user-ID flag and set-group-ID flag
Session ID
Controlling terminal, if any
Signal mask and registered actions
Close-on-exec flag for open file descriptors
Environment variables
Attached shared memory
Resource limits
The parent and child processes have the following differences, however:
The return value from ? is different. The parent has the child process
ID returned. The child process has zero returned.
The process ID values are different.
The parent process ID values are different.
The execution time charged for system and user CPU time starts at zero for the
child process (see  ).
File locks held by the parent are not inherited by the child process.
Child processes do not inherit alarms and timers from the parent process
(and  ). Pending alarms are cleared.
Pending signals for the child process are set to the empty set.
The open file descriptors for the child process are duplicated. This is similar to calling
  for each open file descriptor and giving the duplicated units to the child
process. If the child process performs an on an open file unit, it changes the
file offset for both the parent and child processes for the same file unit. The same
interaction occurs from the parent process on the child's file units.
The operation of the ? system call can be summarized as follows:
1. The kernel makes the current process memory space available virtually in the
new process. Memory pages that are not read-only are marked for "copy-onwrite."
Both processes initially share the same physical memory, marked as
read-only by the kernel. When one or the other process attempts to alter that
page of memory, the kernel copies the page and gives each process its own
writable page.
2. Open file descriptors are duplicated and made available as the same file units
in the child process.
3. Other shareable resources such as attached shared memory segments are made
available to the child process.
4. Other values for the child process are reset (execution time, pending signal set
is cleared, and so on).
5. The ? function establishes the value it is going to return to each process.
The parent process will have the child process ID returned. The child process
will have zero returned.
At this point, before ? returns, the process that will execute first is not defined.
This may be determined by the design of the UNIX scheduler or may be influenced by
the number of processors and load on the system.
 ? 
The synopsis for the ? system call is as follows:

   


  
! ?  "
There are no arguments to the ? system call. When the call is successful, the
parent process receives the process ID of the child process that was created. The child
process, however, receives the return value instead. The child process is always able
to obtain the parent process ID by calling upon   
The caller should always anticipate errors, however. The ? call returns the
value  ! #Jif the function fails. The value of 
will hold the reason for
the error. Possible reasons for failure include $%&%'(when the system-imposed limit
for the number of processes has been exceeded. $()*$*is returned if the system
cannot supply its memory needs.
› 
$()*$*X'
??  
 When this error is returned by ? it
means that the system is lacking the virtual memory resources (or swap space)
required for starting a new process.

Vous aimerez peut-être aussi