note 87828 modified in function.posix-kill by danbrown
| From: | danbrown@php.net | Date: | Fri, 26 Dec 2008 16:50:30 +0000 |
| Subject: | note 87828 modified in function.posix-kill by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-148537@lists.php.net to get a copy of this message | ||
A little recursive function to kill a process and his childs.
it works fine for me and I don't have find something else to do it.
It's a mix of various scripts I've found.
<?php
function killProcessAndChilds($pid,$signal) {
exec("ps -ef| awk '\$3 == '$pid' { print \$2 }'", $output, $ret);
if($ret) return 'you need ps, grep, and awk';
while(list(,$t) = each($output)) {
if ( $t != $pid ) {
killProcessAndChilds($t,$signal);
}
}
//echo "killing ".$pid."\n";
posix_kill($pid, 9);
}
?>
--was--
A little recursive function to kill a process and his childs.
it works fine for me and I don't have find something else to do it.
It's a mix of various scripts I've found.
function killProcessAndChilds($pid,$signal) {
exec("ps -ef| awk '\$3 == '$pid' { print \$2 }'", $output, $ret);
if($ret) return 'you need ps, grep, and awk';
while(list(,$t) = each($output)) {
if ( $t != $pid ) {
killProcessAndChilds($t,$signal);
}
}
//echo "killing ".$pid."\n";
posix_kill($pid, 9);
}
http://php.net/manual/en/function.posix-kill.php