I am using a bat to run a php on win2003 scheduler. Is there a way to check the processes and see if the file is still running.
Asked
Active
Viewed 504 times
4
-
Here you may find some options: http://stackoverflow.com/questions/162291/how-to-check-if-a-process-is-running-via-a-batch-script – Andriy M May 10 '11 at 09:59
3 Answers
1
How about your batch file like this: (pseudocode, as it's been a while)
:makerandom
make som random var, microtime, whatever, we call it %x%
check if file exist, if it does, goto makerandom
call the script with %x% as argument
:check
if file exist %x% goto check
:done
in the php-script:
create the file specified by the argument
... script here ...
delete the file

Bo Persson
- 90,663
- 31
- 146
- 203

David Leonard
- 19
- 1
0
In your scheduled task's .php file: Use getmypid()
to get the PHP process' ID (PID) and save it to a file.
Next time your .php file is called, use $tasks = shell_exec('tasklist.exe');
to get a list of all active processes, then read the previously saved PID and look it up.
Honestly, I don't know if this is the best solution or not.

Philippe Gerber
- 17,457
- 6
- 45
- 40
0
Try out Sysinternals Process Utilities.
http://technet.microsoft.com/en-us/sysinternals/bb896682
The pslist utility is just what you need (given a pid tells if it's running setting an env variable)
Regards
PS: with pslist I suggest evaluating also the pskill utility

BigMike
- 6,683
- 1
- 23
- 24