|
|
|
Process killer is a PHP script that you can run as a cgi to kill a list of process. Better than running "ps -aux", check the pid and then kill it ... this script can help you to automate this task.
Process killer (Unix/linux)
@package
@author Ben Yacoub Hatem <hatem@php.net>
@copyright Copyright (c) 2004
@version $Id$
@access public
| #!/usr/bin/php
<?php
$argv = $GLOBALS[HTTP_SERVER_VARS][argv];
$argc = $GLOBALS[HTTP_SERVER_VARS][argc];
if ($argc != 2 || in_array($argv[1], array('--help', '-help', '-h', '-?'))) {
?> | |
Kill all processes with the same command name
Usage Example:
| <?php echo $argv[0]; ?> <command_name>
Sample (kill all instance of php):
<?php echo $argv[0]; ?> php
<command_name> Command name is the latest value shown
when you run "ps -aux"
Options --help, -help, -h,
and -?, Will return this help
<?php
} else {
$debug = true;
$tokil = $argv[1];
$s = shell_exec("ps -aux");
$data = explode("\n",$s);
foreach($data as $k=>$v){
$v = preg_replace( "/ +/", " ", $v );
$l = explode(" ",$v);
$commands[$l[10]][] = $l[1];
}
$keys = array_keys($commands);
if (!in_array($tokil,$keys )) {
if ($debug) {
echo "No process $tokil to kill.";
}
} else {
foreach($commands[$tokil] as $v){
shell_exec("kill -9 $v");
}
if ($debug) {
echo sizeof($commands[$tokil])." process related to $tokil is killed.";
}
}
}
?> | |
|
|
| UDMSearch - a free search engine, indexing system. Categories : Search Engines, Linux, PHP, MySQL, ODBC | | | ElfReader: An ELF (Executable and Linking Format) header information in PHP. Shows how to use the UNPACK function to read data. Categories : PHP, Linux, PHP Classes | | | Easily Grant Temporary SSH Access to yourself when in remote location Categories : PHP, Linux, Cron, Security | | | PHP class generator, must be used from Command line interface. Categories : PHP, PHP Classes, Shell Scripting | | | Unix Disk Information with graphs Categories : PHP, Shell Scripting, Filesystem | | | PHPBrowser - browsing linux file systems. Categories : PHP, Linux, Filesystem | | | Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP, PHP, HTML, PDF, Excel | | | Call a cgi from php with include function Categories : PHP, CGI | | | Add a linux user from php Categories : Linux, PHP | | | Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs. Categories : Databases, PHP, MySQL, Complete Programs | | | Check if a file exists on a remote FTP server with PHP Categories : PHP, FTP, Regexps | | | Using $PHP_AUTH_USER and $PHP_AUTH_PW to authenticate. Categories : Authentication, PHP | | | file class , uploade file , download file already uploaded on another website Categories : PHP, PHP Classes, Filesystem, Web Services | | | Authorize.net AIM Interface Class v1.0.0 Categories : PHP, PHP Classes, Ecommerce, Payment Gateways | | | Function to remember password Categories : PHP, Authentication, Personalization and Membership | |
| | | | Jose Santos wrote : 1139
It`s very good !!
Kill process is very useful in Linux Operations Systems !!
| | | | Joseph Crawford wrote : 1148
this is a nice script, i mean it shows people how to use php as a shell script rather than a web script however i would still prefer to do kill -9 <pid> personally
i want to make sure the correct process is killed ;)
also i dont see how it can do much i mean it`s either kill -9 <pid or ./script <process name> not much different.
| | | | Ben Yacoub Hatem wrote :1149
the difference in this script is that you can use it if there is many process launched with differents pid ! so in this case u have to kill em one after one ... you see ?
But with this script you can just kill all process with different pid but related to the same app. And you can keep the $debug = true; to be sure that the pid was killed.
| |
|
|
|