blob: ed46f6635e955ac5d21c7f85f027a2ffb91e394e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
void termHandler(int a) {
printf("childterm\n");
}
int fp = 0;
void alarmHandler(int a) {
kill(fp, SIGTERM);
}
int main() {
signal(SIGTERM, &termHandler);
signal(SIGALRM, &alarmHandler);
fp = fork();
if (fp == 0) { // child
pause();
pause();
}
else {
alarm(1);
pause();
alarm(1);
wait(NULL);
}
return 0;
}
|