In-depth understanding of computer systems Chapter VIII exceptional control flow (2)

The process is always in one of three states the following:

run. Either process performed on the CPU, or waiting to be executed and will eventually be the kernel scheduler.
stop. The implementation process is suspended (suspended), and will not be scheduled.
termination. The process never stops. The process will be terminated because of three reasons: 1) to receive a signal, the default behavior of this signal is to terminate the process, 2) return from the main program, 3) exit is called.
Parent process to create a new child process run by calling the fork function.
fork function features:
Called once, twice returned. fork function is called the parent process once, but twice ----- returned once to return to the parent process, once the child is returned to the newly created process.
When a process terminates for any reason, the kernel is not immediately clear it from the system. In contrast, a state is maintained in the process has been terminated until recovered its parent process (reaped). When the parent process of recovery of the child process has been terminated, the kernel exit status of the child process passed to the parent process, and then abandon the process has been terminated, from this point on, the process does not exist. A terminated but has not yet been recovered process called zombie process (zombie).
A process can terminate or stop by calling waitpid function to wait for its children.
Under waitpid function by default (when options = 0) is executing, suspends the calling process until a child process waits for its collection (wait set) is terminated. If a process is waiting for collection at a time just call has been terminated, then the waitpid returns immediately. In both cases, waitpid returns lead to PID has been terminated child process waitpid returned. In this case, the child process has been terminated has been recovered, the kernel will be removed from the system away all traces of it.
Transmitting a signal to the object of the process consists of two distinct steps:
Send a signal. By updating the status of a kernel process context object, sending (delivering) a signal to the destination process. A transmission signal can have the following two reasons: 1) a system event detected by the kernel, such as division by zero or sub-process terminates. 2) a process called kill function, requires kernel explicitly sends a signal to the destination process. A process can send a signal to itself.
receive signal. When the object kernel process is forced to react in some way transmission signal, it receives the signal. Process can ignore this signal, or a termination of the captured signal by performing user level program function called a signal processing (signal handler) is.
 

Guess you like

Origin www.cnblogs.com/zhishuiyushi/p/11794832.html