repositories
/
TD_SE.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
blame
|
history
|
raw
|
HEAD
thread-pid course code.
[TD_SE.git]
/
TD3
/
exo4
/
exo4.c
1
#include <unistd.h>
2
#include <signal.h>
3
#include <sys/wait.h>
4
#include <stdio.h>
5
#include <stdlib.h>
6
7
static void
sigintP
()
8
{
9
printf
(
"pid=%d
\n
"
,
getpid
());
10
signal
(
SIGINT
,
sigintP
);
11
}
12
13
static void
sigalrm
()
14
{
15
exit
(
1
);
16
}
17
18
static void
sigintF
()
19
{
20
signal
(
SIGINT
,
SIG_IGN
);
21
signal
(
SIGALRM
,
sigalrm
);
22
alarm
(
5
);
23
}
24
25
static void
sigchld
()
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
) {
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
}