Subj : Issues with multi-threading and fork To : comp.programming.threads From : jmarant Date : Thu Mar 24 2005 06:36 am Hi, I'm writing a multi-threaded application. A subset of the threads in the application do fork children. Here is basically what is being done: Child: ----- change process user and group change directory redirect standard output and error to a trace file execv a shell script Parent: ------ busy-wait for the child process to terminate by the means of: cnt =3D timeout; while (waitpid (pid , &status, WNOHANG) =3D=3D 0 && cnt !=3D 0) { sleep (1); --cnt; } (I didn't find any other way to implement timeouted waitpid in a mutil-threaded context since one cannot use signals) >From time to times, the timeout mysteriously expires, so I searched for the causes. After some investigation, it seems that the child process hangs right after the fork and does not go further. 'strace -f' shows that it is stuck in a rt_sigsuspend following a sigprocmask(SIG_SETMASK, NULL, ..) which could correspond to __pthread_wait_for_restart_signal, after some diging into the linuxthreads sources. Some additional notes: - The parent process locks mutexes but the child process does not use them, so I think that using pthread_atfork is unnecessary. - I do not use async-signal-unsafe functions within signals and the child is not interrupted by any signal - I removed calls to syslog because it is said to be async-signal-unsafe but it does not change anything. I spent some time searching the Web, and followed some tracks without any success (anything about threading, forking and async-signal-safety). Any idea about what might be happening? Many thanks in advance. -- J=E9r=F4me Marant .