|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2002-08-08 09:56 UTC] alan_k@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 19:00:01 2025 UTC |
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; } ?>