php - Start and monitor process with exec() -


i building laravel app should start external processes , monitor status using process id.

the processes started this, returning pid:

exec('nohup <script> & echo $!'); 

this works fine. have problems tracking status of newly started process, presumably because methods use require checked process child process of shell executing commands.

currently try determine if process still running by:

exec("ps -p $pid -o pid=") == $pid; 

this retruns true if process still running works child processes. should able use kill -0 <pid> here instead, not big problem.

what is problem, though, determining exit code of process. current code looks this:

exec("wait $pid; echo \$?"); 

when process finished, wait should return , write exit code $?. also works child processes of shell executed original command, exit code 127 (is not child of shell).

is there other way of getting exit code of process?

also, use same laravel queue both starting , monitoring processes (with php artisan queue:listen command) exec() methods are called within same process. or php start separare shell each exec() call?

edit: know laravel start new process every queued command starting scripts , monitoring state done in different processes.

the exec() function accepts additional arguments capturing both process output , exit code of process.

example:

exec('nohup <script>', $output, $code); var_dump($code);

should output: int(0) or whatever status code expected.

see http://us2.php.net/manual/en/function.exec.php more.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -