Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.