h0me5k1n Posted August 30, 2007 Share Posted August 30, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/67372-solved-display-if-process-is-running/ Share on other sites More sharing options...
pocobueno1388 Posted August 30, 2007 Share Posted August 30, 2007 Try this out: <?php $check = 'ps -A | grep $PROCESS'; if ($check_result = shell_exec($check)) { // server is running echo '$PROCESS is running.'; } else { echo '$PROCESS is not running'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/67372-solved-display-if-process-is-running/#findComment-338078 Share on other sites More sharing options...
h0me5k1n Posted August 31, 2007 Author Share Posted August 31, 2007 Thanks for the superquick reply Poco - great job Quote Link to comment https://forums.phpfreaks.com/topic/67372-solved-display-if-process-is-running/#findComment-338129 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.