note 96744 added to function.proc-terminate
| From: | mastatimast dot ru at osu1 dot php dot net | Date: | Sat, 13 Mar 2010 19:28:12 +0000 |
| Subject: | note 96744 added to function.proc-terminate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-167004@lists.php.net to get a copy of this message | ||
Method described in the previous note will not work if your child process has his own childs.
There is easier way to solve the problem with non-finishing child processes:
<?php
$descriptorspec = array(
0 => array('pipe', 'r'), // stdin is a pipe that the child will read from
1 => array('pipe', 'w'), // stdout is a pipe that the child will write to
2 => array('pipe', 'w') // stderr is a pipe the child will write to
);
$proc = proc_open('bad_program', $descriptorspec, $pipes);
if(!is_resource($proc)) {
throw new Exception('bad_program could not be started.');
}
// Get current PID
$status = proc_get_status($proc);
$pid = $status['pid'];
// Set process group for the bunch of processes (for easy killing)
posix_setpgid($pid, $pid);
// Some actions
// It's time to kill
// Close pipes
fclose($pipe[0]);
fclose($pipe[1]);
fclose($pipe[2]);
// Send SIGKILL to all processes within group
posix_kill(-$pid, 9);
// Close original process
proc_close($proc);
?>
----
Server IP: 195.54.192.44
Probable Submitter: 127.0.0.1
----
Manual Page -- http://www.php.net/manual/en/function.proc-terminate.php
Edit -- https://master.php.net/note/edit/96744
Del: integrated -- https://master.php.net/note/delete/96744/integrated
Del: useless -- https://master.php.net/note/delete/96744/useless
Del: bad code -- https://master.php.net/note/delete/96744/bad+code
Del: spam -- https://master.php.net/note/delete/96744/spam
Del: non-english -- https://master.php.net/note/delete/96744/non-english
Del: in docs -- https://master.php.net/note/delete/96744/in+docs
Del: other reasons-- https://master.php.net/note/delete/96744
Reject -- https://master.php.net/note/reject/96744
Search -- https://master.php.net/manage/user-notes.php