[ILUG] Signal handling thing
Padraig Brady
padraig at antefacto.com
Wed Jun 26 11:16:09 IST 2002
Sorry I haven't looked at this, but
my motto is don't use signal, use sigaction
for many reasons.
Padraig.
David Neary wrote:
> 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 -----------
>
More information about the ILUG
mailing list