[C/C ++] multi-process: botnets and botnets

Source: Internet
Author: User

[C/C ++] multi-process: botnets and botnets

A zombie process is generated when the parent process calls fork to create a child process, and the child process runs until it is terminated. After a process is terminated, some information is useful to the parent process and kernel, such as the ID of the process, the exit status of the process, and the CPU time of the process. Therefore, after a process is terminated, the system will recycle all the memory allocated to it by the kernel, close the files opened by the process, and keep the above little information for the parent process to use, the system sends a message to the parent process.SIGCHLDSignal, the parent process should be called in timewaitFunction to collect dead parts for sub-processes and make some final work. However, if the parent process is not called in timewaitFunction, the sub-process state becomesZOMBIE, That isBotnets.BotnetsWill occupy memory together and cannot be usedkillKill cleanup, unless the parent process then callswaitThe function or parent process also ends, or the parent process is killed and terminated by other factors,BotnetsWill be recycled.

In the previous article [C/C ++] multi-process: The sample code used by the parent process to listen to the sub-process status wait () is modified to demonstrate zombie processes:

// If (count> CHILD_COUNT) {// change the original CHILD_COUNT to 10 if (count> 10) {FILE * fMain = freopen ("/Users/sodino/workspace/xcode/Define/main.txt", "w", stdout ); // After redirecting the standard output stream of the parent Process, add the following latency code int count = 0; while (1) {printTime (); printf ("Main Process sleep10, count = % d \ n ", count); sleep (10); if (count> 100) {break ;}}

After compilation, run. The effect is as follows:

First, you can directly view the process status during the sub-process running. You can see twoa.outProcess.

After the sub-process prints 10 lines of logs, check the Process status.zombieStatus, that isBotnets.

Use commandskillDrop the parent process, or wait for the parent process to executewaitFunction, you can find that the sub-process has been recycled by the system.

As mentioned at the beginning of this article, the system will sendSIGCHLDSignal, then the next article will talk about how to register the signal listening and processing functions: multi-process: semaphore listening and processing functions.

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.