When a process is terminated, the PCB is erased and the address space and resources used by the terminated process are deallocated. An exit code is placed in its entry in the main process table. The entry is removed once the parent has accepted the exit code. The termination of the process can occur under several conditions:
Abnormal termination of a process can occur when the process itself does something that it shouldn't:
The termination of a process can also be initiated by a user when the process is interactive. The parent process is responsible for the termination/deallocation of its children. The parent process should wait until all its child processes have terminated. When a parent process retrieves a child process's exit code, the child process exits the system normally. The process is in a zombied state until the parent accepts the signal. If the parent never accepts the signal because it has already terminated and exited the system or because it is not waiting for the child process, the child remains in the zombied state until the init process (the original system process) accepts its exit code. Many zombied processes can negatively affect the performance of the system. 3.7.1 The exit() , kill() and abort() CallsThere are two functions a process can call for self termination, exit() and abort() . The exit() function causes a normal termination of the calling process. All open file descriptors associated with the process will be closed. The function will flush all open streams that contain unwritten buffered data, then the open streams are closed. The status parameter is the process's exit status. It is returned to the waiting parent process, which is then restarted. The value of status may be , EXIT_FAILURE , or EXIT_SUCCESS . The value means the process has terminated successfully. The waiting parent process only has access to the lower 8 bits of status . If the parent process is not waiting for the process to terminate, the zombied process is adopted by the init process. The abort() function causes an abnormal termination of the calling process. An abnormal termination of the process causes the same effect as fclose() on all open streams. A waiting parent process will receive a signal that the child process aborted. A process should only abort when it encounters an error that it cannot deal with programmatically.
The kill() function can be used to cause the termination of another process. The kill() function sends a signal to the processes specified or indicated by the parameter pid . The parameter sig is the signal to be sent to the specified process. The signals are listed in the header <signal.h> . To kill a process, sig has the value SIGKILL . The calling process must have the appropriate privileges to send a signal to the process, or it has a real or effective user id that matches the real or saved set user-ID of the process that receives the signal. The calling process may have permission to send only certain signals to processes and not others. If the function successfully sends the signal, is returned to the calling process. If it fails, -1 is returned. The calling process can send the signal to one or several processes under these conditions:
|