actually wait for forked process and return its status -- this is not meant to be a daemon;
--- a/Admin/bash_process/bash_process.c Sat Feb 13 21:22:02 2016 +0100
+++ b/Admin/bash_process/bash_process.c Sat Feb 13 22:52:41 2016 +0100
@@ -7,9 +7,9 @@
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
+#include <sys/wait.h>
#include <unistd.h>
-
static void fail(const char *msg)
{
fprintf(stderr, "%s\n", msg);
@@ -34,8 +34,24 @@
if (setsid() == -1) {
pid_t pid = fork();
+ int status;
+
if (pid == -1) fail("Cannot set session id (failed to fork)");
- else if (pid != 0) exit(0);
+ else if (pid != 0) {
+ if (waitpid(pid, &status, 0) == -1) {
+ fail("Cannot join forked process");
+ }
+
+ if (WIFEXITED(status)) {
+ exit(WEXITSTATUS(status));
+ }
+ else if (WIFSIGNALED(status)) {
+ exit(128 + WTERMSIG(status));
+ }
+ else {
+ fail("Unknown status of forked process");
+ }
+ }
else if (setsid() == -1) fail("Cannot set session id (after fork)");
}