#18804 [Opn->Bgs]: PCNTL variable conflict PARENT-CHILD
| From: | alan_k@php.net | Date: | Thu, 08 Aug 2002 13:56:32 +0000 |
| Subject: | #18804 [Opn->Bgs]: PCNTL variable conflict PARENT-CHILD | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-16273@lists.php.net to get a copy of this message | ||
ID: 18804
Updated by: alan_k@php.net
Reported By: bariou@brasnah.com
-Status: Open
+Status: Bogus
Bug Type: POSIX related
Operating System: linux
PHP Version: 4.2.2
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
please read the fork man page - fork normally copies all the data from
the running process, so your new thread is a copy (not the same data)..
Previous Comments:
------------------------------------------------------------------------
[2002-08-08 09:50:37] bariou@brasnah.com
I can be wrong, but When I make a fork() ($pid=pcntl_fork())the only
difference for the child and parent process is the $pid value. Both
process have the same memory image, credentials, open files, signal
handlers and by the way the same variables. It's not thrue with PCNTL I
dont know for other langages, for exemple try the following test
program => The parent has two variables $a and $b. If I make a change
in the child, this change has no impact on the parent.
Tell me where I'm wrong. Thanks for your help
Marcel
The example for test :
<?php
function sig_handler($signo) {
switch($signo){
case SIGINT:
$msg= "STOP THE WAR\n";
exit();
break;
case SIGHUP:
// handle restart tasks
break;
case SIGCHLD:
while( pcntl_waitpid(-1,$status,WNOHANG)>0 ) {}
break;
default:
// handle all other signals
}
}
pcntl_signal(SIGCHLD, "sig_handler");
pcntl_signal(SIGHUP, "sig_handler");
pcntl_signal(SIGINT, "sig_handler");
$a=10;
$b=10;
while(1){
$c=$a+$b;
echo "\SEPARATOR";
echo "\n I'am the parent C1=> $c ";
sleep(4);
$pid=pcntl_fork();
if($pid==-1){
print "failure\n";}
if(!$pid){
$a=0;
$b=0;
$c=$a+$b;
print "\nI AM THE CHILD C in child => $c";
sleep(4);
exit();
}
print "\n I'm the parent C2=> ".$c;
}
?>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=18804&edit=1