Orphan process with zombie process

Source: Internet
Author: User

The following sections are referenced from https://www.cnblogs.com/Anker/p/3271773.html

First, when each process exits, the kernel frees all of the resources of the process, including the open files, the memory occupied, and so on. However, it still retains certain information (including process ID, exit status of the termination status of the process, run time of the amount of the CPU taken by the Proces s, etc.). It is not released until the parent process passes wait/waitpid (ringer to the child process). After the release of this sub-process is completely disappeared, with the PS command can not be found.

When the child process exits and the kernel frees up all the resources of the child process, the state of the process is the zombie state (Z State) before the parent process is fetched and freed by Wait/waitid, so the zombie state is the process that every process will experience.

To illustrate the problem, it is necessary to understand that the subprocess package is a python-created child process package with two methods, one call and one popen, the difference is that the calling method's parent process is called, Waits for the child process to finish and gives it ringer (the parent process calls wait to get and release the child process ID), then executes, and Popen is different, and then executes its own code after the parent process has created the child process. So, calling call we can't catch a brief moment when the child process becomes a zombie process, and Popen has a way to capture it, and here's the code:

1 Import Time2 Importsubprocess3Child = subprocess. Popen (["Ping","- C","Ten","www.baidu.com"])#after the child process is created, the parent process then executes print4 Print "fffffffffffffffffffffffffffffff"5Time.sleep (40)#The parent process lived for 40 seconds, and the child process died 10 seconds before the parent process died after the child process was dead, and the parent process did not ringer the child process, but did its own thing. This stage of the subprocess is the zombie state. 

If you change the above code Popen to call, you will not catch the moment when the child process becomes zombie, because the parent process waits for the child process to die and ringer it before it executes print.

If, the above code, the parent process is immortal, and has been manufacturing child processes, then as the child process one by one, the remaining information will not be released, the process number will be occupied, but the system can use the process number is limited, if a large number of zombie process generated, The system cannot produce a new process because no process number is available. This is harmful, so avoid the occurrence of this situation.

What is the orphan process? To remove the above code, Time.sleep (40), that is, to let the parent process die earlier than the child process, then the child process is the orphan process, but he will be over the season to the Init process ( at this time with the PS command can see this sub-process Ppid has become 1 ) , the orphan process is not compromised by the fact that Init is doing what the father has done.

Orphan process with zombie process

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.