aboutsummaryrefslogtreecommitdiff
path: root/src/Program.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Program.c')
-rw-r--r--src/Program.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/Program.c b/src/Program.c
index 2c6759e..65164c4 100644
--- a/src/Program.c
+++ b/src/Program.c
@@ -114,6 +114,28 @@ int wait_program(pid_t process_id) {
return WEXITSTATUS(status);
}
+bool wait_program_non_blocking(pid_t process_id, int *status) {
+ int s;
+ int wait_result = waitpid(process_id, &s, WNOHANG);
+ if(wait_result == -1) {
+ perror("waitpid failed");
+ *status = -errno;
+ return false;
+ } else if(wait_result == 0) {
+ /* the child process is still running */
+ *status = 0;
+ return false;
+ }
+
+ if(!WIFEXITED(s)) {
+ *status = -4;
+ return false;
+ }
+
+ *status = WEXITSTATUS(s);
+ return true;
+}
+
int exec_program_async(const char **args, pid_t *result_process_id) {
/* 1 arguments */
if(args[0] == NULL)