Commit | Line | Data |
---|---|---|
01d700ab JB |
1 | #include <unistd.h> |
2 | #include <signal.h> | |
3 | #include <wait.h> | |
4 | #include <stdio.h> | |
5 | #include <stdlib.h> | |
6 | ||
4ed359e8 | 7 | static void sigintP() |
01d700ab | 8 | { |
84f86bf0 JB |
9 | printf("pid=%d\n", getpid()); |
10 | signal(SIGINT, sigintP); | |
01d700ab JB |
11 | } |
12 | ||
4ed359e8 | 13 | static void sigalrm() |
01d700ab | 14 | { |
84f86bf0 | 15 | exit(1); |
01d700ab JB |
16 | } |
17 | ||
4ed359e8 | 18 | static void sigintF() |
01d700ab | 19 | { |
84f86bf0 JB |
20 | signal(SIGINT, SIG_IGN); |
21 | signal(SIGALRM, sigalrm); | |
22 | alarm(5); | |
01d700ab JB |
23 | } |
24 | ||
4ed359e8 | 25 | static void sigchld() |
01d700ab JB |
26 | { |
27 | int status; | |
28 | wait(&status); | |
29 | exit(0); | |
30 | } | |
31 | ||
32 | int main(void) | |
33 | { | |
34 | signal(SIGCHLD, sigchld); | |
35 | if (fork() == 0) { | |
36 | signal(SIGINT, sigintF); | |
37 | while (1) { | |
151a0f56 | 38 | printf("ici fils\n"); |
01d700ab JB |
39 | sleep(1); |
40 | } | |
41 | } | |
42 | while (1) { | |
43 | signal(SIGINT, sigintP); | |
151a0f56 | 44 | printf("ici pere\n"); |
01d700ab JB |
45 | sleep(1); |
46 | } | |
01d700ab | 47 | } |