views:

414

answers:

2

I'm writing a script that builds a queue of other scripts and is supposed to manage their launch. the manager script should know which child process has finished, so it can launch other scripts waiting in the queue.

I added a "& echo $!" to get the Process Id of each child process. so I have my child processes Process Ids, and for now am using system "ps" program call to find if child processes are still running or not.

the thing is that my script currently runs only in Unix-like systems. I don't know how to fetch my children's PID in windows, and my script does not parse "tasklist" command's output in windows yet.

Is there any other way to achieve this? any in-PHP solution to find if the child process is still running? a solution to start other processes (non blocking), and check if they are still running or not.

A: 

You may find Process Control interesting for Unix environments. You may also find an example of executing programs on Windows as comment in the manual, and this points me to think of COM-objects.

Erlend
A: 

What you could do is create a database or file that will hold your process ids. Every process will write his pid (process id) in the file or DB. Use this method to acquire your php pid:

getmypid();

Your supervising process will check every now and then if the process id is still running with the following:

function is_process_running($PID) {
  exec("ps $PID", $ProcessState);
  return(count($ProcessState) >= 2);
}

When process is stopped you can execute the next process

and for use of windows check the comment in the manual: http://no2.php.net/manual/en/book.exec.php#87943

Robert Cabri