Jump to content

PHP PID Check


dog199200

Recommended Posts

Hi I am wondering, how do you do a PID check? I am building a server check that checks to see if a program is running, and if it is it echo's back online but if its not it echo's back offline. The thing is I don't know how to check in the task manager to see if pid of the server file is running. here is what i have so far:

 

 

<?php
$command = shell_exec('TASKLIST /FI "PID eq 3392" /FI "STATUS eq RUNNING"');

if ($command) {

echo 'ONLINE';

} else {

echo 'OFFLINE';

}
?>

 

What that is suppose to do is check the tasklist to see if the PID id is present, and if its not then it fails and says offline, but the problem is that iot always echos back "online" even when the program isn't running :(

 

Link to comment
https://forums.phpfreaks.com/topic/190326-php-pid-check/
Share on other sites

umm i have no idea what you mean, i'm rather new to php :-/ but there is one thing I didn't account for... I didn't know the PID changes :( so the code would then have to look like this:

 

<?php
$PID = "I Don't Know What To Use Here";
$command = shell_exec('TASKLIST /FI "PID eq $PID" /FI "STATUS eq RUNNING"');

if ($command == true && *the same check used to get the pid of the file*) {

echo 'ONLINE';

} else {

echo 'OFFLINE';

}
?>

 

 

I think i went about that the right way :-/ i've looked up PID commands in php and i found none that checks the pid of an external file, just the pid of the running file :(

Link to comment
https://forums.phpfreaks.com/topic/190326-php-pid-check/#findComment-1004109
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.