php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18804 PCNTL variable conflict PARENT-CHILD
Submitted: 2002-08-08 09:50 UTC Modified: 2002-08-08 09:56 UTC
From: bariou at brasnah dot com Assigned:
Status: Not a bug Package: POSIX related
PHP Version: 4.2.2 OS: linux
Private report: No CVE-ID: None
 [2002-08-08 09:50 UTC] bariou at brasnah dot 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;
     }
?>




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-08-08 09:56 UTC] alan_k@php.net
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)..
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jul 22 03:01:29 2024 UTC