Jump to content

[SOLVED] Display if $process is running


h0me5k1n

Recommended Posts

How can I display if a process is running...

 

For example, I'd trying to write a snippet of PHP code that will check if a process is running and display a message on the resulting webpage depending on whether it's running or not:

 

  • "$PROCESS is running"

OR

  • "$PROCESS is not running"

 

In linux I would do this with a bash script as follows:

#!/bin/bash
# Process check
# Usage = $0 <name of process>
TEST=`ps -A | grep $1`
if [ -z "$TEST" ]; then
echo "$1 not running"
else
echo "$1 is running"
fi

 

I'd like to be able to do the same thing but I'm not sure how to do it.  This is what I have so far but it doesn't work:

<?php
$check = 'ps -A | grep $PROCESS';
$check_result = shell_exec($check);
if (!empty($check_result)) {
  // server is running
  echo '$PROCESS is running.';
} else {
  echo '$PROCESS is not running';
} 
?>

 

The use of the $PROCESS variable is only used for the example and isn't important.

Link to comment
https://forums.phpfreaks.com/topic/67372-solved-display-if-process-is-running/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.