I have problems catching signals sent to a multi-threaded process. When
the process receives signals such as SIGINT, SIGSEGV or SIGFPE, it does
not react and keeps frozen, despite my defining a handler for those
signals. If I finally send a kill -9 to unblock it, the telnet that I
used to connect to the FreeBSD machine keeps receiving ^G, beeping and
is unusable.
Here is the code that I compiled :
#include <sys/types.h>
#include <sys/time.h>
#include <sys/signal.h>
#include <pthread.h>
#include <stdio.h>
#include <signal.h>
#include <errno.h>
void sig_handler(int);
void handle_all_sigs();
void *thread_start(void*);
int
main(void)
{
int rc;
long i;
long * ptr;
void* p;
struct itimerval timer_value;
pthread_t handthr;
struct sigaction sigact;
sigset_t sigset;
printf("%d.%d main thread started\n", getpid(), pthread_self());
rc = pthread_create(&handthr, pthread_attr_default, thread_start,
NULL);
if (rc == -1)
{
perror("pthread_create");
return(1);
}
handle_all_sigs();
sigemptyset(&sigset);
for (;;)
{
sigsuspend(&sigset);
break;
}
printf("%d.%d main got out of its loop\n", getpid(), pthread_self());
return(0);
voidQuote:}
sig_handler(int sig)
{
int status=0;
psignal(sig, "signal");
exit(0);
voidQuote:}
handle_all_sigs()
{
int i, rc;
struct sigaction sigact;
int status=0;
/* handle all signals */
sigact.sa_handler = sig_handler;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = 0;
printf("%d.%d handling all signals\n", getpid(), pthread_self());
for (i=1; i<NSIG; i++)
if ((i!=SIGKILL)&&(i!=SIGSTOP))
rc = sigaction(i, &sigact, NULL);
void *Quote:}
thread_start(void *arg)
{
int i;
printf("%d.%d secondary thread started\n", getpid(), pthread_self());
handle_all_sigs(NULL);
/* force a division by zero */
i=0;
i=1/i;
for(;;)
pthread_exit(NULL);
return(NULL);
Any idea of what is wrong ?Quote:}
--
Christophe GOUAULT
Network Department - Information Technology and Systems - Business Unit
Thomson-CSF Detexis (France)
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.