summaryrefslogtreecommitdiff
path: root/ext/pcntl/pcntl.c
diff options
context:
space:
mode:
authorGeorge Schlossnagle <gschlossnagle@php.net>2003-10-28 17:08:18 +0000
committerGeorge Schlossnagle <gschlossnagle@php.net>2003-10-28 17:08:18 +0000
commit797ac80e7cb0be6a6154dff2d1cbc5cd422494a1 (patch)
treea075bb142fbd066faa54f3135d525410b8e0ad62 /ext/pcntl/pcntl.c
parent11754f587c7add1a8fb6e7f2c40cf9f35640578c (diff)
downloadphp-git-797ac80e7cb0be6a6154dff2d1cbc5cd422494a1.tar.gz
Added pcntl_wait, a wraspper around wait()/wait3()
Diffstat (limited to 'ext/pcntl/pcntl.c')
-rwxr-xr-xext/pcntl/pcntl.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c
index 636742f85a..bf581caf7c 100755
--- a/ext/pcntl/pcntl.c
+++ b/ext/pcntl/pcntl.c
@@ -36,7 +36,7 @@
#include "ext/standard/info.h"
#include "php_pcntl.h"
-#if HAVE_GETPRIORITY || HAVE_SETPRIORITY
+#if HAVE_GETPRIORITY || HAVE_SETPRIORITY || HAVE_WAIT3
#include <sys/time.h>
#include <sys/resource.h>
#endif
@@ -46,6 +46,7 @@ ZEND_DECLARE_MODULE_GLOBALS(pcntl)
function_entry pcntl_functions[] = {
PHP_FE(pcntl_fork, NULL)
PHP_FE(pcntl_waitpid, second_arg_force_ref)
+ PHP_FE(pcntl_wait, first_arg_force_ref)
PHP_FE(pcntl_signal, NULL)
PHP_FE(pcntl_wifexited, NULL)
PHP_FE(pcntl_wifstopped, NULL)
@@ -249,6 +250,37 @@ PHP_FUNCTION(pcntl_waitpid)
}
/* }}} */
+/* {{{ proto int pcntl_wait(int &status)
+ Waits on or returns the status of a forked child as defined by the waitpid() system call */
+PHP_FUNCTION(pcntl_wait)
+{
+ long pid, options = 0;
+ zval *z_status = NULL;
+ int status;
+ pid_t child_id;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|l", &z_status, &options) == FAILURE)
+ return;
+
+ convert_to_long_ex(&z_status);
+
+ status = Z_LVAL_P(z_status);
+#ifdef HAVE_WAIT3
+ if(options) {
+ child_id = wait3(&status, options, NULL);
+ }
+ else {
+ child_id = wait(&status);
+ }
+#else
+ child_id = wait(&status);
+#endif
+ Z_LVAL_P(z_status) = status;
+
+ RETURN_LONG((long) child_id);
+}
+/* }}} */
+
/* {{{ proto bool pcntl_wifexited(int status)
Returns true if the child status code represents a successful exit */
PHP_FUNCTION(pcntl_wifexited)