c-daemon-1

This commit is contained in:
Aliberk Sandıkçı 2023-07-26 10:28:17 +03:00
parent 6b21db0dd9
commit ca61ee4ac2
Signed by: asandikci
GPG key ID: 25C67A03B5666BC1
2 changed files with 34 additions and 0 deletions

24
c-daemon/daemon.c Normal file
View file

@ -0,0 +1,24 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/fs.h>
#include <linux/limits.h>
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;
}

10
c-daemon/test.c Normal file
View file

@ -0,0 +1,10 @@
#include <stdio.h>
int _daemon (int, int);
int main(){
getchar();
_daemon(0, 0);
getchar();
return 0;
}