[英]Windows Bat check if php script runnin
I am using a bat to run a php on win2003 scheduler. 我正在使用蝙蝠在win2003调度程序上运行php。 Is there a way to check the processes and see if the file is still running.
有没有办法检查进程,看看文件是否仍在运行。
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: 在PHP脚本中:
create the file specified by the argument
... script here ...
delete the file
In your scheduled task's .php file: Use getmypid()
to get the PHP process' ID (PID) and save it to a file. 在计划任务的.php文件中:使用
getmypid()
获取PHP进程的ID(PID)并将其保存到文件中。
Next time your .php file is called, use $tasks = shell_exec('tasklist.exe');
下次调用.php文件时,请使用
$tasks = shell_exec('tasklist.exe');
to get a list of all active processes, then read the previously saved PID and look it up. 获取所有活动进程的列表,然后读取以前保存的PID并查找它。
Honestly, I don't know if this is the best solution or not. 老实说,我不知道这是不是最好的解决方案。
Try out Sysinternals Process Utilities. 试用Sysinternals Process Utilities。
http://technet.microsoft.com/en-us/sysinternals/bb896682 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) pslist实用程序正是你需要的(给定一个pid告诉它是否正在运行设置一个env变量)
Regards 问候
PS: with pslist I suggest evaluating also the pskill utility PS:使用pslist我建议也评估pskill实用程序
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.