note 27758 added to function.posix-kill

From: Date: Tue, 17 Dec 2002 22:26:44 +0000
Subject: note 27758 added to function.posix-kill
Groups: php.notes 
Request: Send a blank email to php-notes+get-41034@lists.php.net to get a copy of this message
For those that want to kill everything matching a certain pattern (ala killall in for linux), try something like this. Note that this is a good idea to do something like this for cross platform compatilibity, instead of executing killall, because killall for other UNIXes does just that, kills EVERYTHING. :) function killall($match) { if($match=='') return 'no pattern specified'; $match = escapeshellarg($match); exec("ps x|grep $match|grep -v grep|awk '{print $1}'", $output, $ret); if($ret) return 'you need ps, grep, and awk installed for this to work'; while(list(,$t) = each($output)) { if(preg_match('/^([0-9]+)/', $t, $r)) { system('kill '. $r[1], $k); if(!$k) $killed = 1; } } if($killed) { return ''; } else { return "$match: no process killed"; } } -- http://www.php.net/manual/en/function.posix-kill.php http://master.php.net/manage/user-notes.php?action=edit+27758 http://master.php.net/manage/user-notes.php?action=delete+27758 http://master.php.net/manage/user-notes.php?action=reject+27758

« previous php.notes (#41034) next »