0

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.

alexGrac
  • 21
  • 4
  • `The second programs must wait for the output of the first one`. This is the default behaviour. – hek2mgl Sep 04 '14 at 09:23

1 Answers1

0

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.

silkfire
  • 24,585
  • 15
  • 82
  • 105