root / tests / testsig.c @ 1b6b029e
History | View | Annotate | Download (418 Bytes)
1 |
#include <stdlib.h> |
---|---|
2 |
#include <stdio.h> |
3 |
#include <signal.h> |
4 |
#include <unistd.h> |
5 |
|
6 |
void alarm_handler(int sig) |
7 |
{ |
8 |
printf("alarm signal=%d\n", sig);
|
9 |
alarm(1);
|
10 |
} |
11 |
|
12 |
int main(int argc, char **argv) |
13 |
{ |
14 |
struct sigaction act;
|
15 |
act.sa_handler = alarm_handler; |
16 |
sigemptyset(&act.sa_mask); |
17 |
act.sa_flags = 0;
|
18 |
sigaction(SIGALRM, &act, NULL);
|
19 |
alarm(1);
|
20 |
for(;;) {
|
21 |
sleep(1);
|
22 |
} |
23 |
return 0; |
24 |
} |