PHP daemon process + process signal processing

Source: Internet
Author: User
Tags echo date
 
 0) {    exit (0);//parent process exits}//child process becomes new session leader Posix_setsid ();//To prohibit the first sub-process to open the control terminal, need to create a second sub-process, specifically I do not know what principle $pid = Pcntl_fork (); ($pid = =-1) {    exit ("Fork2 failed! \ n ");} ElseIf ($pid > 0) {    exit (0);} echo "Process ID:". posix_getpid (). " \ n "; $open = True;function Sig_handler ($signo) {global $open; switch ($signo) {//Custom signal sigusr1case Sigusr1:echo" Hello, I keep running. n "; break;case Sigterm:echo" and so on the end of this cycle I close \ n "; $open = false;break;default:# code...break;}} Pcntl_signal (SIGUSR1, ' Sig_handler ');p cntl_signal (SIGTERM, ' sig_handler ');//This line of code is important so that each low-level statement is executed to check the signal, Otherwise, the process signal declare (Ticks=1) cannot be detected in an infinite loop, while ($open) {    echo date (' y-m-d h:i:s '). \ n ";    Sleep (1);} echo "I'm out of the box"; exit;
  • 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.