我正在使用bat文件在win2003计划任务中运行php程序。是否有一种方法可以检查进程,并查看该文件是否仍在运行。
我正在使用bat文件在win2003计划任务中运行php程序。是否有一种方法可以检查进程,并查看该文件是否仍在运行。
你的批处理文件可以像这样:(伪代码,因为已经有一段时间了)
: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
在 PHP 脚本中:
create the file specified by the argument
... script here ...
delete the file
getmypid()
获取 PHP 进程的 ID(PID)并将其保存到文件中。$tasks = shell_exec('tasklist.exe');
获取所有活动进程的列表,然后读取先前保存的 PID 并查找它。尝试使用Sysinternals进程工具。
http://technet.microsoft.com/en-us/sysinternals/bb896682
pslist 工具正是你所需要的(给定一个 pid,它会告诉你是否正在运行并设置环境变量)。
谢谢
PS:使用 pslist 工具时,我建议也评估一下 pskill 工具。