
Am 10.02.2011 17:11, schrieb Artyom:
sigset_t set; sigemptyset(& set), sigaddset(& set, SIGCHLD); // SIGTERM, SIGINT, SIGQUIT pthread_sigmask(SIG_BLOCK,& set, ...); int signo( 0); sigwait( set,& signo); switch ( signo) { case SIGCHLD: while (true) { int status( 0); pid_t child = waitpid( -1, % status, WUNTRACED|WCONTINUED); if ( -1 == child&& ECHILD != child) throw runtime_error("waitpid() failed"); // select data/callabck associated with child // from internal storage } case: ... };
correction: if ( -1 == child) { if ( ECHILD == child) { break; // return to sigwait() else { throw runtime_error("waitpid() failed"); } } // select data/callabck associated with child // from internal storage I suggest to wait for SIGUSR1 in sigwait() which indicates that the wait function should be canceld. pthread_kill() can be used to send the SIGUSR1 to the worker-thread. Oliver