From ca61ee4ac26ae3855d41581baba2b44dbabc0cd3 Mon Sep 17 00:00:00 2001 From: asandikci Date: Wed, 26 Jul 2023 10:28:17 +0300 Subject: [PATCH] c-daemon-1 --- c-daemon/daemon.c | 24 ++++++++++++++++++++++++ c-daemon/test.c | 10 ++++++++++ 2 files changed, 34 insertions(+) create mode 100644 c-daemon/daemon.c create mode 100644 c-daemon/test.c diff --git a/c-daemon/daemon.c b/c-daemon/daemon.c new file mode 100644 index 0000000..beca0cf --- /dev/null +++ b/c-daemon/daemon.c @@ -0,0 +1,24 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +int _daemon(int nochdir, int noclose){ + pid_t pid; + // pid_t defined in sys/types.h + // pid_t is a signed int data type + + pid = fork(); // fork of the parent process + // fork() function defined in unistd.h + if (pid < 0){ + exit(EXIT_FAILURE); // exit and EXIT_FAILURE defined in stdlib.h + } + else if (pid > 0){ + exit(EXIT_FAILURE); + } + return 0; +} \ No newline at end of file diff --git a/c-daemon/test.c b/c-daemon/test.c new file mode 100644 index 0000000..7706611 --- /dev/null +++ b/c-daemon/test.c @@ -0,0 +1,10 @@ +#include + +int _daemon (int, int); + +int main(){ + getchar(); + _daemon(0, 0); + getchar(); + return 0; +} \ No newline at end of file