Headers include fix for Mac OS X.
[TD_SE.git] / TD3 / exo4 / exo4.c
... / ...
CommitLineData
1#include <unistd.h>
2#include <signal.h>
3#include <sys/wait.h>
4#include <stdio.h>
5#include <stdlib.h>
6
7static void sigintP()
8{
9 printf("pid=%d\n", getpid());
10 signal(SIGINT, sigintP);
11}
12
13static void sigalrm()
14{
15 exit(1);
16}
17
18static void sigintF()
19{
20 signal(SIGINT, SIG_IGN);
21 signal(SIGALRM, sigalrm);
22 alarm(5);
23}
24
25static void 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}