是否可以获取Windows XP中exec()启动的进程的PID? [英] Is it possible to get the PID of a process launched by exec() in Windows XP?

查看:92
本文介绍了是否可以获取Windows XP中exec()启动的进程的PID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用exec()函数来执行相同的外部程序,并且在某些情况下我想停止其中的一个.但是以下命令:

I am using the exec() function to execute the same external programs, and I want to stop one of them in some case. But the following command:

taskkill /IM program.exe

将杀死所有program.exe.因此,我认为最好的方法是通过其PID终止程序进程.

will get all program.exe killed. So the best way I thought was to kill program process by its PID.

所以,我认为方法是每次执行程序时获取PID,然后将其杀死.

So,I thought the way was to get the PID every time the program was executed, and then kill it.

我正在Windows XP上使用PHP 5.3.

I am using PHP 5.3 on Windows XP.

推荐答案

exec会挂起,直到子进程结束.您需要一个孩子的PID,所以我想您要给一个孩子打个电话.

exec on Windows hangs until child process is over. You need PID of a child, so I suppose you want to nohup a child.

尝试此代码,它对我有用.它没有提示notepad.exe并显示其PID

Try this code, it worked for me. It nohups notepad.exe and displays its PID

    $command = 'notepad.exe';
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->exec("notepad.exe");
print_r ( $oExec->ProcessID ) 

请注意$ WshShell-> exec而不是$ WshShell-> run,这是某些Google资源所声称的.

pay attention to $WshShell->exec and not $WshShell->run as some googled ressources claim.

可以帮助其他人

这篇关于是否可以获取Windows XP中exec()启动的进程的PID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆