Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Via PHP | 10 comments | Create New Account
Click here to return to the 'Via PHP' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Via PHP
Authored by: jon6662412 on Aug 12, '03 09:17:09AM
I read both this hint and the A bash script to kill a process hint, and even read parts of the post where some users said to use the 'killall' command. None worked for my case where the app name contained spaces in the name, like Internet Explorer.app. To make sure I am not nuts, try the above hints yourself because I would prefer a smaller bit of code then what I wrote below. Also it is in PHP, I was not cool enough to write it in a unix shell script.

$process_name = "Internet Explorer.app";

kill_process($process_name);

function kill_process($process_name) 
{
  //**************
  //*KILL_PROCESS*
  //**************

  $cmd = "ps -x";
  echo "cmd = ".$cmd."<br>";
  exec($cmd,$output,$rv);

  while ($element = each($output)) 
  {
    if (ereg($process_name, $element[1])) {
      echo $element[1]."<br>"; // DEBUG THING
      $element[1] = trim($element[1]);
   $pid_array = explode(" ", $element[1]);
      $pid = array_shift($pid_array);
    }
  }

  if (isset($pid)) { 
    $cmd = "kill ".$pid;
    echo "cmd = ".$cmd."<br>";
    exec($cmd,$output,$rv);
  } else {
    echo "NO PID for ".$process_name."<br>";
  }
}


[ Reply to This | # ]