WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

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 : 6014
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  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.";
        }
    }
}
?>




Easily Grant Temporary SSH Access to yourself when in remote location
Categories : PHP, Linux, Cron, Security
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
Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel
How to get IP address in different programming language?
Categories : ASP Components, PHP, Java, CGI
PHPBrowser - browsing linux file systems.
Categories : PHP, Linux, Filesystem
Call a cgi from php with include function
Categories : PHP, CGI
UDMSearch - a free search engine, indexing system.
Categories : Search Engines, Linux, PHP, MySQL, ODBC
Add a linux user from php
Categories : Linux, PHP
Unix Disk Information with graphs
Categories : PHP, Shell Scripting, Filesystem
PHP class generator, must be used from Command line interface.
Categories : PHP, PHP Classes, Shell Scripting
This is a database wrapper for PostgreSQL, but can be simply modified for any other database type.
Categories : Databases, PostgreSQL, PHP
Authorize Me! An authentication script.
Categories : MySQL, Databases, Authentication, PHP
Different Call User Functions
Categories : PHP, Functions, Beginner Guides
How to thread a list of messages in database and show it in a treelike structure
Categories : PHP, MySQL, Databases
Alert in JavaScript and Trace in Flash Action script are two commands that I find very much useful for tracking and debugging errors in my scripts. Unfortunately, there is no such option in PHP.
Categories : PHP, Java Script, Debugging
 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.