| 1 |
/*********************************************************************** |
| 2 |
* Code listing from "Advanced Linux Programming," by CodeSourcery LLC * |
| 3 |
* Copyright (C) 2001 by New Riders Publishing * |
| 4 |
* See COPYRIGHT for license information. * |
| 5 |
***********************************************************************/ |
| 6 |
|
| 7 |
#include <signal.h> |
| 8 |
#include <stdio.h> |
| 9 |
#include <string.h> |
| 10 |
#include <sys/types.h> |
| 11 |
#include <unistd.h> |
| 12 |
|
| 13 |
sig_atomic_t sigusr1_count = 0; |
| 14 |
|
| 15 |
void handler (int signal_number) |
| 16 |
{ |
| 17 |
++sigusr1_count; |
| 18 |
} |
| 19 |
|
| 20 |
int main () |
| 21 |
{ |
| 22 |
struct sigaction sa; |
| 23 |
memset (&sa, 0, sizeof (sa)); |
| 24 |
sa.sa_handler = &handler; |
| 25 |
sigaction (SIGUSR1, &sa, NULL); |
| 26 |
|
| 27 |
/* Do some lengthy stuff here. */ |
| 28 |
/* ... */ |
| 29 |
|
| 30 |
printf ("SIGUSR1 was raised %d times\n", sigusr1_count); |
| 31 |
return 0; |
| 32 |
} |