⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pcntl.c

📁 php-4.4.7学习linux时下载的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*   +----------------------------------------------------------------------+   | PHP Version 4                                                        |   +----------------------------------------------------------------------+   | Copyright (c) 1997-2007 The PHP Group                                |   +----------------------------------------------------------------------+   | This source file is subject to version 3.01 of the PHP license,      |   | that is bundled with this package in the file LICENSE, and is        |   | available through the world-wide-web at the following url:           |   | http://www.php.net/license/3_01.txt                                  |   | If you did not receive a copy of the PHP license and are unable to   |   | obtain it through the world-wide-web, please send a note to          |   | license@php.net so we can mail you a copy immediately.               |   +----------------------------------------------------------------------+   | Author: Jason Greene <jason@inetgurus.net>                           |   +----------------------------------------------------------------------+ *//* $Id: pcntl.c,v 1.28.4.6.2.2 2007/01/01 09:46:45 sebastian Exp $ */#define PCNTL_DEBUG 0#if PCNTL_DEBUG#define DEBUG_OUT printf("DEBUG: ");printf#define IF_DEBUG(z) z#else#define IF_DEBUG(z)#endif#ifdef HAVE_CONFIG_H#include "config.h"#endif#include "php.h"#include "php_ini.h"#include "ext/standard/info.h"#include "php_pcntl.h"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_signal,		NULL)	PHP_FE(pcntl_wifexited,		NULL)	PHP_FE(pcntl_wifstopped,	NULL)	PHP_FE(pcntl_wifsignaled,	NULL)	PHP_FE(pcntl_wexitstatus,	NULL)	PHP_FE(pcntl_wtermsig,		NULL)	PHP_FE(pcntl_wstopsig,		NULL)	PHP_FE(pcntl_exec,			NULL)	PHP_FE(pcntl_alarm,			NULL)	{NULL, NULL, NULL}	};zend_module_entry pcntl_module_entry = {	STANDARD_MODULE_HEADER,	"pcntl",	pcntl_functions,	PHP_MINIT(pcntl),	PHP_MSHUTDOWN(pcntl),	PHP_RINIT(pcntl),	PHP_RSHUTDOWN(pcntl),	PHP_MINFO(pcntl),	NO_VERSION_YET,	STANDARD_MODULE_PROPERTIES};#ifdef COMPILE_DL_PCNTLZEND_GET_MODULE(pcntl)#endifstatic void pcntl_signal_handler(int);static void pcntl_tick_handler();  void php_register_signal_constants(INIT_FUNC_ARGS){	/* Wait Constants */#ifdef WNOHANG	REGISTER_LONG_CONSTANT("WNOHANG",  (long) WNOHANG, CONST_CS | CONST_PERSISTENT);#endif#ifdef WUNTRACED	REGISTER_LONG_CONSTANT("WUNTRACED",  (long) WUNTRACED, CONST_CS | CONST_PERSISTENT);#endif	/* Signal Constants */	REGISTER_LONG_CONSTANT("SIG_IGN",  (long) SIG_IGN, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIG_DFL",  (long) SIG_DFL, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIG_ERR",  (long) SIG_ERR, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIGHUP",   (long) SIGHUP,  CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIGINT",   (long) SIGINT,  CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIGQUIT",  (long) SIGQUIT, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIGILL",   (long) SIGILL,  CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIGTRAP",  (long) SIGTRAP, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIGABRT",  (long) SIGABRT, CONST_CS | CONST_PERSISTENT);#ifdef SIGIOT	REGISTER_LONG_CONSTANT("SIGIOT",   (long) SIGIOT,  CONST_CS | CONST_PERSISTENT);#endif	REGISTER_LONG_CONSTANT("SIGBUS",   (long) SIGBUS,  CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIGFPE",   (long) SIGFPE,  CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIGKILL",  (long) SIGKILL, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIGUSR1",  (long) SIGUSR1, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIGSEGV",  (long) SIGSEGV, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIGUSR2",  (long) SIGUSR2, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIGPIPE",  (long) SIGPIPE, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIGALRM",  (long) SIGALRM, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIGTERM",  (long) SIGTERM, CONST_CS | CONST_PERSISTENT);#ifdef SIGSTKFLT	REGISTER_LONG_CONSTANT("SIGSTKFLT",(long) SIGSTKFLT, CONST_CS | CONST_PERSISTENT);#endif #ifdef SIGCLD	REGISTER_LONG_CONSTANT("SIGCLD",   (long) SIGCLD, CONST_CS | CONST_PERSISTENT);#endif#ifdef SIGCHLD	REGISTER_LONG_CONSTANT("SIGCHLD",  (long) SIGCHLD, CONST_CS | CONST_PERSISTENT);#endif	REGISTER_LONG_CONSTANT("SIGCONT",  (long) SIGCONT, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIGSTOP",  (long) SIGSTOP, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIGTSTP",  (long) SIGTSTP, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIGTTIN",  (long) SIGTTIN, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIGTTOU",  (long) SIGTTOU, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIGURG",   (long) SIGURG , CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIGXCPU",  (long) SIGXCPU, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIGXFSZ",  (long) SIGXFSZ, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIGVTALRM",(long) SIGVTALRM, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIGPROF",  (long) SIGPROF, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIGWINCH", (long) SIGWINCH, CONST_CS | CONST_PERSISTENT);#ifdef SIGPOLL	REGISTER_LONG_CONSTANT("SIGPOLL",  (long) SIGPOLL, CONST_CS | CONST_PERSISTENT);#endif	REGISTER_LONG_CONSTANT("SIGIO",    (long) SIGIO, CONST_CS | CONST_PERSISTENT);#ifdef SIGPWR	REGISTER_LONG_CONSTANT("SIGPWR",   (long) SIGPWR, CONST_CS | CONST_PERSISTENT);#endif	REGISTER_LONG_CONSTANT("SIGSYS",   (long) SIGSYS, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("SIGBABY",  (long) SIGSYS, CONST_CS | CONST_PERSISTENT);}static void php_pcntl_init_globals(zend_pcntl_globals *pcntl_globals){ 	memset(pcntl_globals, 0, sizeof(*pcntl_globals));}PHP_RINIT_FUNCTION(pcntl){	zend_hash_init(&PCNTL_G(php_signal_table), 16, NULL, ZVAL_PTR_DTOR, 0);	PCNTL_G(head) = PCNTL_G(tail) = PCNTL_G(spares) = NULL;	return SUCCESS;}PHP_MINIT_FUNCTION(pcntl){	php_register_signal_constants(INIT_FUNC_ARGS_PASSTHRU);	ZEND_INIT_MODULE_GLOBALS(pcntl, php_pcntl_init_globals, NULL);	php_add_tick_function(pcntl_tick_handler);	return SUCCESS;}PHP_MSHUTDOWN_FUNCTION(pcntl){	return SUCCESS;}PHP_RSHUTDOWN_FUNCTION(pcntl){	struct php_pcntl_pending_signal *sig;	/* FIXME: if a signal is delivered after this point, things will go pear shaped;	 * need to remove signal handlers */	zend_hash_destroy(&PCNTL_G(php_signal_table));	while (PCNTL_G(head)) {		sig = PCNTL_G(head);		PCNTL_G(head) = sig->next;		efree(sig);	}	while (PCNTL_G(spares)) {		sig = PCNTL_G(spares);		PCNTL_G(spares) = sig->next;		efree(sig);	}	return SUCCESS;}PHP_MINFO_FUNCTION(pcntl){	php_info_print_table_start();	php_info_print_table_header(2, "pcntl support", "enabled");	php_info_print_table_end();}/* {{{ proto int pcntl_fork(void)   Forks the currently running process following the same behavior as the UNIX fork() system call*/PHP_FUNCTION(pcntl_fork){	pid_t id;	id = fork();	if (id == -1) {		php_error(E_ERROR, "Error %d in %s", errno, get_active_function_name(TSRMLS_C));	}		RETURN_LONG((long) id);}/* }}} *//* {{{ proto int pcntl_alarm(int seconds)   Set an alarm clock for delivery of a signal*/PHP_FUNCTION(pcntl_alarm){	long seconds;	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &seconds) == FAILURE)		return;		RETURN_LONG ((long) alarm(seconds));}/* }}} *//* {{{ proto int pcntl_waitpid(long pid, long status, long options)   Waits on or returns the status of a forked child as defined by the waitpid() system call */PHP_FUNCTION(pcntl_waitpid){	long pid, options = 0;	zval *z_status = NULL;	int status;	pid_t child_id;	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz|l", &pid, &z_status, &options) == FAILURE)		return;		convert_to_long_ex(&z_status);	status = Z_LVAL_P(z_status);	child_id = waitpid((pid_t) pid, &status, options);	Z_LVAL_P(z_status) = status;	RETURN_LONG((long) child_id);}/* }}} *//* {{{ proto bool pcntl_wifexited(long status)    Returns true if the child status code represents a successful exit */PHP_FUNCTION(pcntl_wifexited){#ifdef WIFEXITED	zval **status;	int status_word;		if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &status) == FAILURE) {		WRONG_PARAM_COUNT;	}		status_word = (int) Z_LVAL_PP(status);		if (WIFEXITED(status_word)) RETURN_TRUE;#endif	RETURN_FALSE;}/* }}} *//* {{{ proto bool pcntl_wifstopped(long status)    Returns true if the child status code represents a stopped process (WUNTRACED must have been used with waitpid) */PHP_FUNCTION(pcntl_wifstopped){#ifdef WIFSTOPPED	zval **status;	int status_word;		if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &status) == FAILURE) {		WRONG_PARAM_COUNT;	}		status_word = (int) Z_LVAL_PP(status);		if (WIFSTOPPED(status_word)) RETURN_TRUE;#endif	RETURN_FALSE;}/* }}} *//* {{{ proto bool pcntl_wifsignaled(long status)    Returns true if the child status code represents a process that was terminated due to a signal */PHP_FUNCTION(pcntl_wifsignaled){#ifdef WIFSIGNALED	zval **status;	int status_word;		if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &status) == FAILURE) {		WRONG_PARAM_COUNT;	}		status_word = (int) Z_LVAL_PP(status);		if (WIFSIGNALED(status_word)) RETURN_TRUE;#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -