Discussion on the defunct process of Unix ("zombie" process)

Source: Internet
Author: User
I recently read Steven S's "Unix environment programming". Chapter 8 describes process control, which contains descriptions of zombie processes, but I still don't know much about it.

There is an article about the defunct process of UNIX on the InternetArticleThe description of its principles is more detailed and useful, so it is reprinted here.

From: http://www2.ccw.com.cn Author: Zhang daoxin Zhao Guoming

In UNIX system management, when the ps command is used
When observing the execution status of a process, we often see that the status bar of some processes is defunct. This is the so-called "zombie" process. The "zombie" process is a long-dead process, but in the progress table
(Processs
Table) still occupies a position (slot ). Because the capacity of the input table is limited, the defunct process not only occupies the system memory resources, but also affects the system performance.
Too many projects will cause system paralysis.

We know that every UNIX process has an entry in the Process Table, the coreProgramAll information used when the process is executed
Are stored at the entry point. When you use the ps command to view the process information in the system, you will see the relevant data in the Process Table. After a new process is created using a fork () system call, the core process
The table assigns an entry point to the new process, and stores the relevant information in the process table corresponding to the entry point. One of these information is the identifier of the parent process. When this process completes its own Lifecycle
It will execute the exit () system call. At this time, the data in the original process will be called by the exit code (exit
Code), CPU time used for execution, and other data will be retained until the system passes it to its parent process. It can be seen that the time when the defunct process appears is
After the process is terminated, but the parent process has not read the data. With this, we can use the following program to create a defunct process:

1 # Include < Stdio. h >
2 # Include < Sys / Main. h >
3 # Include < Stdlib. h >
4 # Include < Unistd. h >
5
6 Int Main ()
7 {
8 If ( ! Fork ())
9 {
10Printf ("child PID= %D \ n ", getpid ());
11Exit (0)
12}
13 Sleep ( 20 );
14 Printf ("Parent PID = % D \ n ", getpid ());
15 Exit ( 0 );
16 }

When
When the above program is executed in a later way, 8th lines force the program to sleep for 20 seconds, so that the user has time to enter the PS-e command to observe the process status. After the parent process is terminated, use PS
-E command observation, we will find that the defunct process also disappears. This is because after the parent process is terminated, the INIT process takes over the "orphan process" (orphan
Process), and after these orphan processes are executed, the entry points in the process will be deleted. If a program is designed to be defective, the parent process of a process may remain sleep.
If the sub-process is in an endless loop, it becomes a defunct process after the sub-process is executed. The defunct process may remain in the system until the system restarts.

If we slightly modify the above program, we will execute wait () or waitpid () system call before the 8th-line sleep () system call, then, the child process immediately returns the data in the table to the parent process after termination, and the system immediately deletes the entry point. In this case, the defunct process is not generated.

Because the Scheduler cannot select the defunct process, the kill command cannot be used to delete the defunct process. The only method is to restart the system.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.