waitpid.c

来自「java 到c的转换程序的原代码.对喜欢C程序而不懂JAVA程序的人很有帮助」· C语言 代码 · 共 40 行

C
40
字号
/* Routine to handle blocking waits using conditions, signals, and * non-blocking waits. This prevent the entire system from freezing * when wait() is called. */#include <sys/types.h>#include <sys/wait.h>#include <errno.h>#include "scout_semaphore.h"struct Semaphore waitSema;pid_t__wrap_waitpid(pid_t pid, int *status, int options){    int ret;    if ((options & WNOHANG) != 0) {	return __real_waitpid(pid, status, options);    } else {	while ((ret = __real_waitpid(pid, status, (options | WNOHANG))) == 0) {	    /* There are no children ready to be waited on, so 	     * wait on a semaphore that SIGCHLD will broadcast. */	    semaphoreWait(&waitSema);	}	return ret;    }}voidwaitSignal() {    semaphoreSignalAll(&waitSema);}voidwaitInit() {    semaphoreInit(&waitSema, 0);}

⌨️ 快捷键说明

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