The birth and demise of Linux process

Births, process

(1), process 0 and process 1 (intrinsic kernel inside)

(2), fork vfork function and the function used to generate new process

2, the process of extinction

(1), normal termination and abnormal termination

(2) the process at run time consuming system resources (memory, IO), these resources should fully released when the process terminates (if the process is still not released the demise of these resources will result in the loss of resources).

(3), Linux system design requirements: when each process exits, the operating system will automatically recover all the resources of the process involved (for example, when the contents of malloc application is not free, currently this memory will be released at the end of the process, such as open open the document does not close, it will be closed at program termination). But the operating system only recovered memory and IO consumption during this process to work, but did not recover the process itself uses memory (8KB, mainly task_struct (this structure is mainly a description of the process) and stack memory)

(4) because the process itself is 8KB memory the operating system can not be recycled, so they need someone to assist recovery, so we each process needs a help it "corpses" of the people, this person is the parent process of the process.

3, zombie process

(1), the father of the child before the end of the process. After the child process the parent process at this time is not necessarily immediately be able to help the child process "corpses" in this section (the child process has ended and that the parent has not already done it, "corpses") child process is called a zombie process.

(2), in addition to the child process task_struct and begin to clean up the stack memory space remaining.

(3), the parent process may be used to wait or waitpid reclaim memory resources remain to be explicitly recovered and sub-process state acquired child process exits.

(4), the parent process can not use wait or waitpid recover the child, they would recover the remaining resources to be recovered memory of the child when the parent process ends at this time. (This is designed to prevent the parent forgot to explicitly call wait, waitpid to recover the child process resulting in a memory leak)

4, orphaned

(1), the parent process before the end of the child process, the child process to become an orphan process.

(2), Linux System requirements: All orphaned automatically became a special process (process 1, which is the init process) of the child process. (The purpose of this design is to avoid memory leaks).

Guess you like

Origin www.cnblogs.com/jiangtongxue/p/11234262.html