Linux multi-process concurrency service __ On the method of child process recycling

Source: Internet
Author: User

In the case of the Tcpserv service program:

1) Parent Process: Responsible for system initialization, as well as listening (listen), accepting connection request (accept), where accept default blocking call.

2) Each receive a connection request, dynamic new (fork) a child process, task completion or client disconnection, service subprocess needs to be retired

and recover system resources.

3) The recovery of the design subprocess for Linux requires the parent process to participate (wait calls), while the main service of the process is monitored

The client connection request, while blocking in the (accept) call, so the parent process itself is unable to "fen" to do the child process recycling calls.

4) The problem now is how to find a service portal for the parent process to complete the process reclamation call.

There are 2 methods:

1) using the signal mechanism, a soft interrupt is generated by the operating system into the process Signal Service program, which executes the recycle call of the child process.

Registers the sigchild signal in the attached process (signal/sigaction) and executes the waitpid call in the signal processing function.

Question: Is the signaling mechanism reliable? In particular, the dynamic request response scenario for large frequency high loads is addressed.

2) Start a new standalone thread pthread in the parent process, specifically responsible for performing the recycle call, at which time the wait is used to block

The call is more appropriate if the use of Waitpid requires constant loop waiting. Note The wait call is immediate when there are no child processes

Failed to return. (The parent process can make a registration when it fork the child process).

5) In many cases, we can consider multithreading concurrency instead of multi-process concurrency, eliminating a lot of problems.

Linux multi-process concurrency service __ On the method of child process recycling

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.