Reputation: 717
I'm trying to find the PID of a background system call I'm making from a php webpage. If I call 'ps -A' from within the PHP script and print it to my browser, it doesn't have the same output as calling 'ps -A' from my terminal. This is particularly frustrating because I can see the PID of the background process that PHP called from my terminal, but not from within PHP.
In other words, my code looks like this:
system("process &");
system("ps -A");
But that doesn't produce the same output as calling 'ps -A' from the terminal. Not only that, but 'process' shows up in terminal, but not from the PHP call.
Can anybody explain to me why this is and how I could get the PID of 'process' from within my PHP code? (For the record, I've also tried using variations of the code including using exec() and passthru(), none of which have worked so far.)
Thanks.
Upvotes: 3
Views: 1989
Reputation: 695
echo $!
will get the PID of the last command, so..
system("process & echo $!");
Upvotes: 2