]> granicus.if.org Git - php/commitdiff
Added nice() function, which allows changing of priority for the current
authorIlia Alshanetsky <iliaa@php.net>
Tue, 18 Feb 2003 01:07:57 +0000 (01:07 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Tue, 18 Feb 2003 01:07:57 +0000 (01:07 +0000)
process.

ext/standard/basic_functions.c
ext/standard/config.m4
ext/standard/exec.c
ext/standard/exec.h

index 13259305116ba6f5bfa872ffb3762364a6d59c9b..942d38138067e70a40d9f69be7dca2907400b815 100644 (file)
@@ -424,6 +424,10 @@ function_entry basic_functions[] = {
        PHP_FE(proc_get_status,                                                                                                 NULL)
 #endif
 
+#ifdef HAVE_NICE
+       PHP_FE(nice,                                                                                                            NULL)   
+#endif
+
        PHP_FE(rand,                                                                                                                    NULL)
        PHP_FE(srand,                                                                                                                   NULL)
        PHP_FE(getrandmax,                                                                                                              NULL)
index 28a945f0b7ce127e22102cdc73fe976c3ba9842d..293218455220c1e19bcb5ddf8de021c53d143161 100644 (file)
@@ -274,6 +274,11 @@ PHP_CHECK_FUNC(res_nsend, resolv, bind, socket)
 PHP_CHECK_FUNC(dn_expand, resolv, bind, socket)
 dnl already done PHP_CHECK_FUNC(dn_skipname, resolv, bind, socket)
 
+dnl
+dnl Check for the availability of the nice function
+dnl
+PHP_CHECK_FUNC(nice)
+
 PHP_NEW_EXTENSION(standard, array.c base64.c basic_functions.c browscap.c crc32.c crypt.c \
                             cyr_convert.c datetime.c dir.c dl.c dns.c exec.c file.c filestat.c \
                             flock_compat.c formatted_print.c fsock.c head.c html.c image.c \
index 13ed72a6ac55b9042188a205a2566e67c42ee38d..d37dcb6cd6067702d61f1fa05e78152ddc477d78 100644 (file)
 #include <fcntl.h>
 #endif
 
+#if HAVE_NICE && HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
 /* {{{ php_Exec
  * If type==0, only last line of output is returned (exec)
  * If type==1, all lines will be printed and last lined returned (system)
@@ -487,6 +491,29 @@ PHP_FUNCTION(shell_exec)
 }
 /* }}} */
 
+#ifdef HAVE_NICE
+/* {{{ proto bool nice(int priority)
+   Change the priority of the current process */
+PHP_FUNCTION(nice)
+{
+       long pri;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &pri) == FAILURE) {
+               RETURN_FALSE;
+       }
+
+       errno = 0;
+       nice(pri);
+       if (errno) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Only a super user may attempt to increase the process priority.");
+               RETURN_FALSE;
+       }
+       
+       RETURN_TRUE;
+}
+/* }}} */
+#endif
+
 /*
  * Local variables:
  * tab-width: 4
index 796701317f4d8c08fc78a9f633280066fb8d0d81..fd1c5e39c58949a0dd4ec6c372f84fe6f697529d 100644 (file)
@@ -31,6 +31,7 @@ PHP_FUNCTION(proc_open);
 PHP_FUNCTION(proc_get_status);
 PHP_FUNCTION(proc_close);
 PHP_FUNCTION(proc_terminate);
+PHP_FUNCTION(nice);
 PHP_MINIT_FUNCTION(proc_open);
 
 char *php_escape_shell_cmd(char *);