PHP implementation of multi-process in the Linux environment, how the subclass does not produce defunct

Source: Internet
Author: User

<?PHP//use Pcntl_fork () to generate child processes when the program needs to fork, and then perform the tasks simultaneously in multiple threads    $pid=pcntl_fork (); if($pdi< 0)         Exit(' Fork error! '); if($pid) {        //if the PID is greater than 0, then it is the parent process,//This side let the parent process directly return data to the client, to achieve the effect of the fact        #dothing}Else {        //child processes, allowing the child process to perform complex business logic. Let it sleep 100s        Sleep(100); }    /*above this way, has been able to implement multi-threaded simultaneous processing, but, the child process has been running, then 1, the process has been there, the Linux system will be consumed by the death of 2, the client page has been in the Refresh page, customer experience poor 
     */    //solve the problem: the//Sub-process executes the code logic and exits its die () or exit () directly, freeing up the resources it occupies.            But there is a problem, producing n multiple defunct (zombie process)//Then how to eliminate the zombie process//1, the parent class uses pcntl_wait () to wait for the child process to end and recycle it. 2, defined at the beginning of the page, allowing the system to automatically recycle the zombie process (note: After the child process is finished, you must die or exit or exec (' kill-9 '. Posix_getpid ()))Pcntl_signal (SIGCLD,sig_ign); Pcntl_signal (SIGCHLD, sig_ign);

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.