dog199200 Posted January 30, 2010 Share Posted January 30, 2010 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 More sharing options...
trq Posted January 30, 2010 Share Posted January 30, 2010 Your only checking that shell_exec() has executed correctly (hence its always true). You need to check the string contained within $command and see what it holds. Link to comment https://forums.phpfreaks.com/topic/190326-php-pid-check/#findComment-1004104 Share on other sites More sharing options...
dog199200 Posted January 30, 2010 Author Share Posted January 30, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.