linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Problem with exiting threads under NPTL
@ 2003-12-14  5:25 Petr Vandrovec
  2003-12-14 15:02 ` Martin Schlemmer
  2003-12-14 19:38 ` [patch] " Ingo Molnar
  0 siblings, 2 replies; 23+ messages in thread
From: Petr Vandrovec @ 2003-12-14  5:25 UTC (permalink / raw)
  To: linux-kernel

Hi,
  several times one of our threads ended up as ZOMBIE and
nobody wants to pick him up - even init ignores it. Inspection
of kernel structures revealed that task's exit code is 0,
exit_signal is -1, ptrace is 0 and state is 8 (ZOMBIE).

   Quick look at exit_notify reveals that it should not happen:
if task has exit_signal == -1 and is not ptraced, we should immediate
move to TASK_DEAD and get rid of task as fast as possible.

   But problem is that in do_notify_parent we have code which
sets exit_signal to -1 if parent ignores SIGCHLD, and we call
do_notify_parent() for group leader from release_task() when
last member of thread group exits, without taking any care
about eventual changes in exit_signal field.

   So if some process ignores SIGCHLD, and spawns child process 
which creates additional thread, and main thread in child exits 
before child it created, you'll end up with immortal zombie.

						Best regards,
							Petr Vandrovec
							vandrove@vc.cvut.cz

F   UID   PID  PPID PRI  NI   VSZ  RSS WCHAN  STAT TTY        TIME COMMAND
5     0  3709     1  15   0     0    0 exit   Z    tty3       0:00 [test] <defunct>


Creator of immortal zombies:

#include <pthread.h>
#include <signal.h>
#include <unistd.h>
#include <stdio.h>

static void* thread(void* dummy) {
	/* Make sure that we exit as second thread */
        sleep(1);
        return NULL;
}

void main(void) {
        int pid;

        signal(SIGCHLD, SIG_IGN);

        pid = fork();
        if (pid == 0) {
                pthread_t p;

                pthread_create(&p, NULL, thread, NULL);
        } else {
                /* Sleep some time so we know that child threads exit before us */
                sleep(2);
                printf("Look for task %d...\n", pid);
        }
}


^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2003-12-15 23:15 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-14  5:25 Problem with exiting threads under NPTL Petr Vandrovec
2003-12-14 15:02 ` Martin Schlemmer
2003-12-14 19:38 ` [patch] " Ingo Molnar
2003-12-14 20:38   ` Linus Torvalds
2003-12-14 20:45     ` Linus Torvalds
2003-12-14 21:02       ` Ingo Molnar
2003-12-15 15:04       ` Jörn Engel
2003-12-14 21:06     ` Ingo Molnar
2003-12-14 22:10       ` Linus Torvalds
2003-12-14 22:17         ` Ingo Molnar
2003-12-14 22:32           ` Linus Torvalds
2003-12-15 23:04             ` Roland McGrath
2003-12-14 22:28         ` Ingo Molnar
2003-12-14 22:45           ` Linus Torvalds
2003-12-14 23:08             ` Ingo Molnar
2003-12-15  6:31               ` dan carpenter
2003-12-15 11:43                 ` Ingo Molnar
2003-12-15 13:07                   ` dan carpenter
2003-12-15 15:11                 ` Linus Torvalds
2003-12-15 23:15               ` Roland McGrath
2003-12-15  8:54         ` Arjan van de Ven
2003-12-15 22:55           ` Roland McGrath
2003-12-15 23:06     ` Roland McGrath

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).