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