-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCommon.h
49 lines (43 loc) · 1.26 KB
/
Common.h
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef _COMMON_H_
#define _COMMON_H_
#include "Defs.h"
void kill_child_handler(int sig)
{
int status;
pid_t done = waitpid(-1, // Any child
&status,
0); // Blocked mode.
if (done == -1)
{
printf("No more child processes.\n");
}
else
{
short isNormalTermination = WIFEXITED(status);
if (!isNormalTermination ||
// WEXITSTATUS should be used only if normal termination = true.
(isNormalTermination && WEXITSTATUS(status) != 0))
{
printf("Zombie for PID -- %d failed.\n", done);
exit(EXIT_FAILURE);
}
else
{
printf("Zombie for PID -- %d successfully removed.\n", done);
}
}
}
void handle_child_finishing()
{
// Handle child process killing.
struct sigaction kill_child_signal;
kill_child_signal.sa_handler = kill_child_handler;
sigemptyset(&kill_child_signal.sa_mask);
kill_child_signal.sa_flags = SA_RESTART; // Mark handler as Permanent.
if (sigaction(SIGCHLD, &kill_child_signal, 0) == -1)
{
perror("Error of calling sigaction");
exit(EXIT_FAILURE);
}
}
#endif /* _COMMON_H_ */