pb: catching signals in a multi-threaded process

pb: catching signals in a multi-threaded process

Post by christophe.goua.. » Thu, 24 Jun 1999 04:00:00



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);

Quote:}

void
sig_handler(int sig)
{
   int status=0;

   psignal(sig, "signal");
   exit(0);

Quote:}

void
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);

Quote:}

void *
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);

Quote:}

Any idea of what is wrong ?
--
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.

 
 
 

1. Multi-threaded application thread stops receiving signals

We are currently running a multi-threaded application under 64-bit
Solaris 8 on E420 server.  These threads manage client connections to
a the server.  We keep a single thread to manage the log files and the
connection threads.  it wakes up periodically and checks to see if the
connection threads have been idle for more that 5 minutes.  If so, it
sends a signal to close the connection.

The problem we are seeing is that this management thread processes
fine for a while but eventually gets to the point where any signals
sent to it never arrive.  Because the signals never process it never
manages the connection threads or the log files after it gets into
this state.

This Application appears to run fine when compiled and run on Solaris
2.6.  Has anyone seen any problems with threaded apps on Solaris 8 or
e420's?  We have just applied the most recent patch sets to see if it
would solve the problem.

thanks,
Bill Lewis

2. Unix Support Programmer in Vancouver,BC

3. Design of a server: multi-threaded or multi-processes?

4. Ide kernel & parallel printing

5. another problem with signal in a multi-threaded environment

6. anyone else seen this?

7. signal in Solaris's multi-threaded environment

8. NFS Mount Permissions Problems

9. Core dumps from multi-threaded processes?

10. Multi-thread process -threads in different schedulers?

11. profiling a multi-threaded process

12. C++ Exceptions in Multi-threaded Solaris Process

13. problem with close socket on a multi-threaded process