Subj : threaded program and wait() call To : comp.programming.threads From : tadek Date : Fri Aug 05 2005 04:28 pm Hello, I posted similar request to comp.unix.programmer, but since I don't see it there and this group deals specifically with threads, please let me present my problem and ask for help. OS: RHEL4 Linux, i386 platform and i686 hardware (glibc-2.3.4-2.9) Process creates two threads. In the 'main' thread module, I install signal handler for SIGTERM and SIGHUP. The 'main' thread creates 'worker' thread and and then loops checking wheather 'worker' loop is alive (pseudo code): .... while (bWorkerDead == FALSE) sleep(5); status = pthread_kill (thread_parms.sWorkerThread.tid, 0); if (status != EOK) ... if(g_shutdown) pthread_kill(thread_parms.sWorkerThread.tid, SIGHUP); ... When SIGTERM is delivered to the signal handler, global flag (g_shutdown) is set and in the loop above SIGHUP is sent to worker thread. (I do make sure that SIGHUP is sent only once). The 'worker' thread spawns n number of independent processes using posix_spawn() function and when done, calls wait() function, waiting for any child process to exit or for signal (SIGHUP). Unfortunately SIGHUP is not delivered to the 'worker' thread (pseudo code) ... loop posix_spawn(); // start child processes while() // monitor them if( SIGHUP received) loop kill spawned processes .... pid=wait(); // wait for child process to die/exit if (pid == (pid_t)-1) if (EINTR == errno) // signal received (SIGHUP expected) continue; else ... if (WIFEXITED(iStatVal)) ..... etc; I ported above code from QNX to Linux and I was expecting to behave identically: when child process exits - it gets restarted, when SIGHUP is deliver - 'worker' thread should kill all spawned child processes. The call to wait() never returns as the result of signal delivery (pid==-1). My signal handler receives SIGHUP. Is anything missing in the logic above? Tad Dragowski PS I am also confused whether I am using LinuxThreads or NPTL when linking with glibc and making calls to pthread_* functions. .