Bug #74685 [Opn->Csd]: signal listion is wrong

From: Date: Mon, 21 Aug 2017 08:21:12 +0000
Subject: Bug #74685 [Opn->Csd]: signal listion is wrong
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-210761@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74685&edit=1 ID: 74685 User updated by: shan dot liu at msn dot com Reported by: shan dot liu at msn dot com Summary: signal listion is wrong -Status: Open +Status: Closed Type: Bug Package: PCNTL related Operating System: Linux PHP Version: 7.1.3 Block user comment: N Private report: N New Comment: may be not a bug... Previous Comments: ------------------------------------------------------------------------ [2017-06-02 02:12:10] shan dot liu at msn dot com i try c code,is work: ```c #include <stdio.h> #include <stdlib.h> #include <signal.h> void signal_test(int signal_num){ printf("%d",getpid()); fflush(stdout); } int main(){ if(!fork()){//child sleep(100); return EXIT_SUCCESS; } //on parent process register signal function signal(SIGTERM,signal_test); int t,c; while(1){ c=wait(t); if(c==-1)break; } return EXIT_SUCCESS; } ``` on term: [root@rabbitmq-node02 gs]# gcc t.c -o t [root@rabbitmq-node02 gs]# ./t & [1] 77776 [root@rabbitmq-node02 gs]# kill 77776 //kill parent processes is output.. 77776[root@rabbitmq-node02 gs]# //why php is child all exit,The signal function begins to execute ------------------------------------------------------------------------ [2017-06-02 02:06:30] shan dot liu at msn dot com i try c code,is normal: ```c #include <stdio.h> #include <stdlib.h> #include <signal.h> void signal_test(int signal_num){ printf("%d",getpid()); fflush(stdout); } int main(){ if(!fork()){ sleep(100); return EXIT_SUCCESS; } signal(SIGTERM,signal_test); int t,c; while(1){ c=wait(t); if(c==-1)break; } return EXIT_SUCCESS; } ``` on term: [root@rabbitmq-node02 gs]# gcc t.c -o t [root@rabbitmq-node02 gs]# ./t & [1] 77776 [root@rabbitmq-node02 gs]# kill 77776 //kill parent processes is output.. 77776[root@rabbitmq-node02 gs]# //why php is child all exit,The signal function begins to execute ------------------------------------------------------------------------ [2017-06-02 01:41:13] shan dot liu at msn dot com Why the child process exit before parent process on receiving the signal? ------------------------------------------------------------------------ [2017-06-02 01:23:21] requinix@php.net You're misunderstanding what is happening. Change the child's sleep to 10 seconds, run, kill the parent, and DON'T kill the child. Just wait. ------------------------------------------------------------------------ [2017-06-02 01:20:17] shan dot liu at msn dot com PHP CODE: <?php pcntl_fork() && exit; $parent = posix_getpid(); if ($child = pcntl_fork()) { echo "parent: parent is " . posix_getpid() . "\n"; echo "parent: child is {$child}\n"; echo "parent running\n"; } else { echo "child running\n"; sleep(1000); //child processes not register signal exit;//child processes stop here } //only parent run this code... pcntl_signal(SIGTERM, function() use ($child) { echo $child ? "parent sigterm\n" : "child sigterm\n"; }); declare(ticks = 1){ while (true){ //on term kill parent processes ,no response //but i kill child processes,parent processes receive a term signal,why? $pid=pcntl_wait($status); if($pid==-1)break; } } ?> // test history... // [root@rabbitmq-node02 gs]# php -v // PHP 7.1.3 (cli) (built: Mar 21 2017 10:38:32) ( NTS ) // Copyright (c) 1997-2017 The PHP Group // Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies // with Zend OPcache v7.1.3, Copyright (c) 1999-2017, by Zend Technologies // [root@rabbitmq-node02 gs]# php tt.php // parent: parent is 77506 // parent: child is 77507 // parent running // child running // [root@rabbitmq-node02 gs]# kill 77506 // kill parent processes,No output // [root@rabbitmq-node02 gs]# kill 77507 //kill child processes,parent processes receive a term signal,why,child not register signal function // [root@rabbitmq-node02 gs]# parent sigterm ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=74685 -- Edit this bug report at https://bugs.php.net/bug.php?id=74685&edit=1

« previous php.bugs (#210761) next »