PHPBuilder - Check if a program is running



RSS Twitter
Snippets Other

Check if a program is running

by: Michiel Hazelhof
|
April 13, 2004

Version: 1.1

Type: Sample Code (HOWTO)

Category: Other

License: GNU General Public License

Description: Check if a program is running and print up or down based on the pidof command. This should be 100% accurate.



This is the normal version and just displays up or down in plain tekst.
<?php
$return_var = exec('pidof $app_name');
  if ($return_var>0) {
      echo "Up";
      }
  if ($return_var==0) {
      echo "DOWN";
      }
?>



Fancy version
<?php
$return_var = exec('pidof $app_name');
  if ($return_var>0) {
      echo "<b><font color=blue>Up</font></b>";
      }
  if ($return_var==0) {
      echo "<b><font color=red>DOWN</font></b>";
      }
?>


Fancy version with pid showing when the app is up
<?php
$return_var = exec('pidof $app_name');
  if ($return_var>0) {
      echo "<b><font color=blue>Up</font></b>, with pid: ";
      echo $return_var;
      }
  if ($return_var==0) {
      echo "<b><font color=red>DOWN</font></b>";
      }
?>

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Michiel Hazelhof

Comment:



Comment:

(Maximum characters: 1200). You have characters left.