WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Process killer for *nix
Categories : PHP, CGI, Shell Scripting, Linux Click here to Update Your Picture
Ben Yacoub Hatem
Date : Jun 26th 2004
Grade : 4 of 5 (graded 2 times)
Viewed : 3626
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Ben Yacoub Hatem
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

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 &lt;pid&gt; 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 &lt;pid or ./script &lt;process name&gt; 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.