Back to index

glibc  2.9
tst-signal.c
Go to the documentation of this file.
00001 #include <signal.h>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include <string.h>
00005 
00006 int win = 0;
00007 
00008 static void
00009 handler (int sig)
00010 {
00011   printf ("Received signal %d (%s).\n", sig, strsignal(sig));
00012   win = 1;
00013 }
00014 
00015 int
00016 main (void)
00017 {
00018   if (signal (SIGTERM, handler) == SIG_ERR)
00019     {
00020       perror ("signal: SIGTERM");
00021       exit (EXIT_FAILURE);
00022     }
00023 
00024   puts ("Set handler.");
00025 
00026   printf ("Sending myself signal %d.\n", SIGTERM);
00027   fflush (stdout);
00028 
00029   if (raise (SIGTERM) < 0)
00030     {
00031       perror ("raise: SIGTERM");
00032       exit (EXIT_FAILURE);
00033     }
00034 
00035   if (!win)
00036     {
00037       puts ("Didn't get any signal.  Test FAILED!");
00038       exit (EXIT_FAILURE);
00039     }
00040 
00041   puts ("Got a signal.  Test succeeded.");
00042 
00043   return EXIT_SUCCESS;
00044 }