Page 1 of 1

need help in getting processes list

Posted: Fri Nov 07, 2008 6:16 am
by susrisha
I have a program Scheduler.exe which acts like a server for certain processing.
I want to have a php program which can check if this program is running and if not, start it.
I also need a php program which can stop it likewise.

I am running the program in Windows. Is there any possible way to do this?

Re: need help in getting processes list

Posted: Fri Nov 07, 2008 7:37 am
by Hannes2k
Hi,
hmm. I think there is no DOS command for listening the running processes. So you have to write a second program which lists you the running processes.
After that, you can check the output of this programm and starting your schedule.exe.

Unter Linux this would be much easier, because you just have to call 'ps' in php, then starting the programm (with 'schedule &') and killing it by 'kill schedule' or 'kill PID'.

Re: need help in getting processes list

Posted: Fri Nov 07, 2008 7:53 am
by susrisha
Hi, after going through the post, i realized there is no way i can do it directly by php. So i wrote two batch files which will do that work and am simply doing an exec on them.

Here is the sample code if it might help any one. to start the server:

Code: Select all

 
tasklist /FI "IMAGENAME eq SMSScheduler.exe" /FO CSV > search.log
 
FOR /F %%A IN (search.log) DO IF %%~zA EQU 0 GOTO end
 
 
 
CD "E:\Naresh\java\SMSScheduler\SMSScheduler\bin\Release" //location of the exe file
e:
start SMSScheduler.exe serverconfig.xml //command to execute the program
 
:end
 
del search.log
EXIT
 
 
This will start the server and if already running, it will just ignore and return back.

Now to stop the server:

Code: Select all

 
tasklist /FI "IMAGENAME eq SMSScheduler.exe" /FO CSV > search1.log
 
FOR /F %%A IN (search.log) DO IF %%~zA EQU 0 GOTO end
 
 
@echo off
TASKKILL /F /IM "SMSScheduler.exe" //name of the process to look into
:end
 
del search1.log
 
 
This has worked for me quite well.. except that when i call the php to start server, it will not be able to return me anything first time since it executes forever. This problem i solved by just putting an alert to the user that if there is no response for five seconds, just stop in browser and retry. :)