diff options
author | George Schlossnagle <gschlossnagle@php.net> | 2003-10-28 17:08:18 +0000 |
---|---|---|
committer | George Schlossnagle <gschlossnagle@php.net> | 2003-10-28 17:08:18 +0000 |
commit | 797ac80e7cb0be6a6154dff2d1cbc5cd422494a1 (patch) | |
tree | a075bb142fbd066faa54f3135d525410b8e0ad62 /ext | |
parent | 11754f587c7add1a8fb6e7f2c40cf9f35640578c (diff) | |
download | php-git-797ac80e7cb0be6a6154dff2d1cbc5cd422494a1.tar.gz |
Added pcntl_wait, a wraspper around wait()/wait3()
Diffstat (limited to 'ext')
-rw-r--r-- | ext/pcntl/config.m4 | 2 | ||||
-rwxr-xr-x | ext/pcntl/pcntl.c | 34 | ||||
-rw-r--r-- | ext/pcntl/php_pcntl.h | 1 |
3 files changed, 35 insertions, 2 deletions
diff --git a/ext/pcntl/config.m4 b/ext/pcntl/config.m4 index 84cac889c2..4b6b99441a 100644 --- a/ext/pcntl/config.m4 +++ b/ext/pcntl/config.m4 @@ -13,7 +13,7 @@ if test "$PHP_PCNTL" != "no"; then AC_CHECK_FUNCS(fork, [ AC_DEFINE(HAVE_FORK,1,[ ]) ], [ AC_MSG_ERROR(pcntl: fork() not supported by this platform) ]) AC_CHECK_FUNCS(waitpid, [ AC_DEFINE(HAVE_WAITPID,1,[ ]) ], [ AC_MSG_ERROR(pcntl: fork() not supported by this platform) ]) AC_CHECK_FUNCS(sigaction, [ AC_DEFINE(HAVE_SIGACTION,1,[ ]) ], [ AC_MSG_ERROR(pcntl: sigaction() not supported by this platform) ]) - AC_CHECK_FUNCS(getpriority setpriority) + AC_CHECK_FUNCS(getpriority setpriority wait3) PHP_NEW_EXTENSION(pcntl, pcntl.c php_signal.c, $ext_shared, cli) fi 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) diff --git a/ext/pcntl/php_pcntl.h b/ext/pcntl/php_pcntl.h index 212db2994e..dbea8ca174 100644 --- a/ext/pcntl/php_pcntl.h +++ b/ext/pcntl/php_pcntl.h @@ -42,6 +42,7 @@ PHP_MINFO_FUNCTION(pcntl); PHP_FUNCTION(pcntl_alarm); PHP_FUNCTION(pcntl_fork); PHP_FUNCTION(pcntl_waitpid); +PHP_FUNCTION(pcntl_wait); PHP_FUNCTION(pcntl_wifexited); PHP_FUNCTION(pcntl_wifstopped); PHP_FUNCTION(pcntl_wifsignaled); |