From 3c2d695e58a73f5d35a0dbc794b7d4b82a9841fe Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Fri, 4 Jun 2021 10:09:47 -0400 Subject: Added `fork_proc()`. Which handles forking a process, aswell as exiting the parent process. --- pullreqd.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'pullreqd.c') diff --git a/pullreqd.c b/pullreqd.c index 8161c8d..a690b3e 100644 --- a/pullreqd.c +++ b/pullreqd.c @@ -7,3 +7,17 @@ #include #include #include + +pid_t fork_proc() { + /* Fork off the parent. */ + pid_t pid = fork(); + + /* The process id is non zero, so it must be the parent process. */ + if (pid) { + /* Exit with EXIT_FAILURE if the parent's pid is + * negative, otherwise exit with EXIT_SUCCESS. + */ + exit((pid < 0) ? EXIT_FAILURE : EXIT_SUCCESS); + } + return pid; +} -- cgit v1.2.3-13-gbd6f