#18804 [NEW]: PCNTL variable conflict PARENT-CHILD
| From: | bariou at brasnah dot com | Date: | Thu, 08 Aug 2002 13:50:37 +0000 |
| Subject: | #18804 [NEW]: PCNTL variable conflict PARENT-CHILD | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-16271@lists.php.net to get a copy of this message | ||
From: bariou@brasnah.com
Operating system: linux
PHP version: 4.2.2
PHP Bug Type: POSIX related
Bug description: PCNTL variable conflict PARENT-CHILD
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 bug report at http://bugs.php.net/?id=18804&edit=1
--
Fixed in CVS: http://bugs.php.net/fix.php?id=18804&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=18804&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=18804&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=18804&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=18804&r=support
Expected behavior: http://bugs.php.net/fix.php?id=18804&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=18804&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=18804&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=18804&r=globals