We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e7eb052 commit 31b5729Copy full SHA for 31b5729
multithreading/Common.h
@@ -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
26
27
+ printf("Zombie for PID -- %d successfully removed.\n", done);
28
29
30
+}
0 commit comments