note 77047 added to ref.pcntl

From: Date: Mon, 13 Aug 2007 00:16:41 +0000
Subject: note 77047 added to ref.pcntl
Groups: php.notes 
Request: Send a blank email to php-notes+get-129430@lists.php.net to get a copy of this message
ok, heres what ya do to handle child process's ... :> you want to pfork your main program, and let it exit, allowing the new child to become the main program (parent process). example psudo code : main program start; .... if pfork'd child ok then exit ; // now your new child process is in control... // use a signal handler to make it exit (sigkill or sigterm probably) // when this new process pforks, store the new child PID's in an // array. when your process catch's the sigterm signal // loop thru the array of its child PID's sending each child // sigkill , then call pwait on them to wait for them to exit. // this will make sure any child process are cleaned up ok // THEN .. now here's the trick.... // reset yer sigterm handler BACK to its original default handler, // thennnnn raise sigterm , main program will exit ok now tooooo :> example: when your pfork'd main process gets sigterm ... then do something like this : foreach ($this->pForkList as $kiddie) { $deadPID = 0; $this->sendSignal(SIGKILL,$kiddie); do { $deadPID = pcntl_waitpid(-1,WNOHANG); if ($deadPID > 0) { // kiddie has exited now ... unset($this->pForkList[ array_search($deadPID,$this->pForkList)]); break; } // end if } while ($deadPID == 0); } // end for // now reset sigterm ... $this->signalSet($sigNum,SIG_DFL); // RAISE sigterm now ... $this->sendSignal(SIGTERM,$this->myPID); this will allow your main process and all its child process's to exit properly and not leave and zombies or other bad stuff behind ! ---- Server IP: 69.147.83.197 Probable Submitter: 71.83.212.119 ---- Manual Page -- http://www.php.net/manual/en/ref.pcntl.php Edit -- https://master.php.net/note/edit/77047 Del: integrated -- https://master.php.net/note/delete/77047/integrated Del: useless -- https://master.php.net/note/delete/77047/useless Del: bad code -- https://master.php.net/note/delete/77047/bad+code Del: spam -- https://master.php.net/note/delete/77047/spam Del: non-english -- https://master.php.net/note/delete/77047/non-english Del: in docs -- https://master.php.net/note/delete/77047/in+docs Del: other reasons-- https://master.php.net/note/delete/77047 Reject -- https://master.php.net/note/reject/77047 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#129430) next »