[ILUG] Signal handling thing

From: David Neary (dneary at domain wanadoo.fr)
Date: Wed 26 Jun 2002 - 10:52:50 IST


Hi all,

This is kind of puzzling me - I'm sure I've done stuff similar to
this a million tomes, but I'm having trouble getting this
working. Can anyone see what I'm doing wrong here?

Basically I'm expecting signal 42 (MYSIG) to be raised an
indefinite number of times, until I raise SIGINT in the usual
manner. But I'm getting a system "Real-time signal 10" message,
and the program exits, after the first call (presumably, when my
sign-handler's called a second time). Any idea why? Something
idiotic I'm missing?

Cheers,
Dave.

------- test_signal.c ------------

#include <signal.h> /* Signal stuff */
#include <stdlib.h> /* exit() */
#include <errno.h>
#include <stdio.h> /* fprintf() */

enum custom_sigs{
  MY_SIG=42
}; /* Name signals - just out of habit. */

void custom_signal(int sig)
{
  fprintf(stderr, "My signal got raised. It's signal number %d.\n", sig);
}
    
void interrupt(int sig)
{
  fprintf(stderr, "Received a SIGINT signal - quitting\n");
  exit(0);
}

int main(void)
{
  if(signal(SIGINT, interrupt) == SIG_ERR)
  {
    perror("Signal attach failed!!!\n");
    exit(1);
  }

  if(signal(MY_SIG, custom_signal) == SIG_ERR)
    {
      perror("Custom signal attach failed!!!\n");
      exit(1);
    }

  while(1)
    raise(MY_SIG); /* To break the loop, interrupt (Ctrl-C) */

  return 0;
}

------- EOF -----------

-- 
       David Neary,
    Marseille, France
  E-Mail: bolsh at domain gimp.org


This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:17:33 GMT