简体   繁体   中英

PID of external process launched in PHP

I need obtain the PID of a process executed in PHP. A overview of my problem is the next:

I have a script wich execute two external programs (process in MatLab). The second programs must to wait the output of the first one and I need the PID of these process to kill them if the user wants it.

First I used exec() but I have any idea how get the pid. Also I have used proc_open() but I need that the first call blocks the script (the input for the second script will be stored in a temporal directory, is an image) until the first process ends.

My enviroment is in Windows. Thanks in advance.

You can get the PID of a process with the help of WMIC. Make sure that only one (unique) process with that name is running though:

exec('wmic process where name="program.exe" get ProcessID 2>&1', $output);

$pid = $output[1];

Replace program.exe with the name of your relevant process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM