note 63729 deleted from function.exec by cmb
| From: | cmb@php.net | Date: | Mon, 21 Nov 2016 19:18:03 +0000 |
| Subject: | note 63729 deleted from function.exec by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-207287@lists.php.net to get a copy of this message | ||
Note Submitter:
----
I've done a C program to act as a "timeout controller" process, by forking itself and
executing some other command received as parameter.
Then, in PHP I have a function that calls commands this way:
<?php
...
$command = "tout_controller <tout> <command_name> <command_args>"
exec($command,$status);
echo "Exit status code of command is $status";
...
?>
I've noticed that exit status code returned from a C process is a "special" integer.
I wanted "command" exit status code to be returned to controller, and then controller to
exit with same status code (to get this status from PHP).
Exit status was always 0 !!!
To solve this, i've found a C macro to use inside tout_controller:
<C code snippet>
..
waitpid(pid,&status,0); // wait for process that execs COMMAND
..
//exit(status); // that doesn't work
exit(WEXITSTATUS(ret)); // that's ok
..
</C code snippet>
It isn't exactly a PHP note, but may be useful to help some desperated programmer's ;)