[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Manager thread becomes zombie ..........................
From: |
mnayak |
Subject: |
Manager thread becomes zombie .......................... |
Date: |
Mon, 8 Oct 2001 15:33:47 +0530 |
Hi,
I am getting a Zombie(my manager thread becomes zombie) , when I am running
following program on my system.
#include<stdio.h>
#include<pthread.h>
#include<string.h>
#include<signal.h>
#include<sys/types.h>
#include<sys/wait.h>
pthread_t thr1;
pthread_t thr2;
pthread_mutex_t mm;
void (*func_ptr1)(void *);
void (*func_ptr2)(void *);
void print_str1(void);
void print_str2(void);
main()
{
int ret_val = 1;
void *temp_ptr;
sigset_t set;
/* Create a thread thr1 */
ret_val = pthread_create( &thr1, NULL, (void *)print_str1, NULL );
/* Create thread thr2 */
ret_val = pthread_create( &thr2, NULL, (void *)print_str2, NULL );
/*
** Set the signal mask.
** Here SIGINT is being masked in the main thread.
*/
sigemptyset(&set);
sigaddset(&set,SIGINT);
sigprocmask(SIG_SETMASK, &set, NULL);
/* Infinite loop to keep the thread alive */
while( 1 ) {}
return;
}
/******** Funtion for thread 1**************/
void print_str1()
{
int count = 0;
/* Infinite loop to keep the thread alive */
while( 1 ) {}
return;
}
/******** Funtion for thread 2**************/
void print_str2()
{
int count = 0;
/* Infinite loop to keep the thread alive */
while( 1 ) {}
return;
}
complie above program as follows :
gcc -o test -static test.c -lpthread
run the progarm saying ./test
when the program is running in a indefinite loop, open other terminal & try
to kill one thread using
kill -2 process id of child threads( ps -aef | grep ./test shows all
threads including thier pid).
main thread didn't get killed as it blocks SIGINT( signal no 2) signals.
but two child threads got killed & manager thread
becomes zombie.
My system is having following configuration.
System : Linux version 2.4.10(address@hidden) (gcc version 2.96
20000731 ( Red Hat Linux 7.1 2.96-81))#1 wed
oct 3 19:55:09 IST 2001
Architecture : i686
addons : linuxthreads
I think , this is happening due to manager thread exiting without any
waitpid() waiting for it.
problem is happening due to following steps.
1. one child thread get killed due to our using SIGINT.
2. when child thread get killed it sends __pthread_sig_cancel to manager
thread( because manager thread creates child thread
using clone and one argument to clone is __pthread_sig_cancel , so when
child dies it sends __pthread_sig_cancel.
3. manager threads handles cancel signal & makes terminated_child is 1, so
pthread_reap_children gets called.
4.In pthread_reap_children , manager thread sends SIGINT signal to any
other child thread & main thread.
5. Main thread has masked the SIGINT signal , so it didn't die.After
sending signal to child threads & main thread
manager thead exits , but main thread is not using waitpid() call to
handle the exit status of manager thread, so manager
thread becomes zombie
I have a solution for it as follows .
Actually when main thread creates manager thread through clone(), it should
give __pthread_sig_cancel in one of argument.so
that when manager thread dies , it will send a cancel signal to main
thread(it's parent) .main thread can use pthread_handle_sigcancel
to handle it. just calling waitpid () for manager thread in
pthread_handle_sigcancel.
I need your suggestion regarding it.
Thanks
Manoj Nayak
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Manager thread becomes zombie ..........................,
mnayak <=