]> granicus.if.org Git - php/commitdiff
Added pcntl_wait, a wraspper around wait()/wait3()
authorGeorge Schlossnagle <gschlossnagle@php.net>
Tue, 28 Oct 2003 17:08:18 +0000 (17:08 +0000)
committerGeorge Schlossnagle <gschlossnagle@php.net>
Tue, 28 Oct 2003 17:08:18 +0000 (17:08 +0000)
ext/pcntl/config.m4
ext/pcntl/pcntl.c
ext/pcntl/php_pcntl.h

index 84cac889c215bc079f1caced349b8b18eb0d39a0..4b6b99441adf417d08c7a935f446ac9bc1f015df 100644 (file)
@@ -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
index 636742f85a01195566c6146c569fbab1b197da91..bf581caf7c8cc121de0a931c81598dfdaddf6b69 100755 (executable)
@@ -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)
index 212db2994e28bcc7423b107389a22f0f1ddcc7af..dbea8ca17498aaef8ad726f31a1be8280938e2c8 100644 (file)
@@ -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);