note 102765 added to function.pcntl-signal
| From: | AurelienMarchand at osu1 dot php dot net | Date: | Fri, 04 Mar 2011 15:22:34 +0000 |
| Subject: | note 102765 added to function.pcntl-signal | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-177565@lists.php.net to get a copy of this message | ||
I was having some issues with processing a signal using an object method I use for something else as
well. In particular, I wanted to handle SIGCHLD with my own method "do_reap()" which I
also call after a stream_select timeout and that uses a non-blocking pcntl_waitpid function.
The method was called when the signal was received but it couldn't reap the child.
The only way it worked was by creating a new handler that itself called do_reap().
So in other words, the following does not work:
class Parent {
/* ... */
private function do_reap(){
$p = pcntl_waitpid(-1,$status,WNOHANG);
if($p > 0){
echo "\nReaped zombie child " . $p;
}
public function run(){
/* ... */
pcntl_signal(SIGCHLD,array(&$this,"do_reap"));
$readable = @stream_select($read,$null,$null,5); // 5 sec timeout
if($readable === 0){
// we got a timeout
$this->do_reap();
}
}
But this work:
class Parent {
/* ... */
private function do_reap(){
$p = pcntl_waitpid(-1,$status,WNOHANG);
if($p > 0){
echo "\nReaped zombie child " . $p;
}
public function run(){
/* ... */
pcntl_signal(SIGCHLD,array(&$this,"child_died"));
$readable = @stream_select($read,$null,$null,5); // 5 sec timeout
if($readable === 0){
// we got a timeout
$this->do_reap();
}
private function child_died(){
$this->do_reap();
}
}
----
Server IP: 66.207.199.35
Probable Submitter: 209.202.82.139
----
Manual Page -- http://www.php.net/manual/en/function.pcntl-signal.php
Edit -- https://master.php.net/note/edit/102765
Del: integrated -- https://master.php.net/note/delete/102765/integrated
Del: useless -- https://master.php.net/note/delete/102765/useless
Del: bad code -- https://master.php.net/note/delete/102765/bad+code
Del: spam -- https://master.php.net/note/delete/102765/spam
Del: non-english -- https://master.php.net/note/delete/102765/non-english
Del: in docs -- https://master.php.net/note/delete/102765/in+docs
Del: other reasons-- https://master.php.net/note/delete/102765
Reject -- https://master.php.net/note/reject/102765
Search -- https://master.php.net/manage/user-notes.php