Bug #74685 [Fbk->Opn]: signal listion is wrong
| From: | shan dot liu at msn dot com | Date: | Fri, 02 Jun 2017 01:20:18 +0000 |
| Subject: | Bug #74685 [Fbk->Opn]: signal listion is wrong | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-209350@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: Feedback
+Status: Open
Type: Bug
Package: PCNTL related
Operating System: Linux
-PHP Version: 7.1.5
+PHP Version: 7.1.3
Block user comment: N
Private report: N
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2017-06-02 01:17:29] shan dot liu at msn dot com
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;
}
}
// [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
------------------------------------------------------------------------
[2017-06-01 10:40:34] requinix@php.net
> kill parent id,not output
> kill child id,is output:parent id
I think you have that backwards. Are you sure you were killing the right processes?
Here's a test script I just wrote: https://pastebin.com/vwGiFYGT
It all seems to be working correctly for me.
------------------------------------------------------------------------
[2017-06-01 09:42:42] requinix@php.net
Oh, wait, I misread that.
------------------------------------------------------------------------
[2017-06-01 09:40:53] requinix@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php
If you can provide more information, feel free to add it
to this bug and change the status back to "Open".
Thank you for your interest in PHP.
signal_pro won't fire if you kill the parent, and when you kill the child posix_getpid will
return the PID of the current process (which is the parent).
What do you think it should do?
------------------------------------------------------------------------
[2017-06-01 09:34:55] shan dot liu at msn dot com
Description:
------------
//
<?php
if(pcntl_fork())die();
$fp = pcntl_fork();
if (!$fp) {
//child
sleep(300);
exit;
}
//parent
function signal_pro($signo){
echo posix_getpid();
};
pcntl_signal(SIGTERM,'signal_pro');
declare(ticks = 1){
while (true){
$pid=pcntl_wait($status);
if($pid==-1)break;
}
}
?>
//linux shell
kill parent id,not output
kill child id,is output:parent id
signal listen is wong???
Test script:
---------------
<?php
if(pcntl_fork())die();
$fp = pcntl_fork();
if (!$fp) {
//child
sleep(300);
exit;
}
//parent
function signal_pro($signo){
echo posix_getpid();
};
pcntl_signal(SIGTERM,'signal_pro');
declare(ticks = 1){
while (true){
$pid=pcntl_wait($status);
if($pid==-1)break;
}
}
?>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74685&edit=1