Skip to content

Commit 31b5729

Browse files
optiklaboptiklab
optiklab
authored and
optiklab
committed
Added common library file.
1 parent e7eb052 commit 31b5729

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

multithreading/Common.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <sys/wait.h>
2+
3+
#define EXIT_FAILURE 1
4+
5+
void kill_child_handler(int sig)
6+
{
7+
int status;
8+
pid_t done = waitpid(-1, // Any child
9+
&status,
10+
0); // Blocked mode.
11+
if (done == -1)
12+
{
13+
printf("No more child processes.\n");
14+
}
15+
else
16+
{
17+
short isNormalTermination = WIFEXITED(status);
18+
if (!isNormalTermination ||
19+
// WEXITSTATUS should be used only if normal termination = true.
20+
(isNormalTermination && WEXITSTATUS(status) != 0))
21+
{
22+
printf("Zombie for PID -- %d failed.\n", done);
23+
exit(EXIT_FAILURE);
24+
}
25+
else
26+
{
27+
printf("Zombie for PID -- %d successfully removed.\n", done);
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)