c-daemon-1
This commit is contained in:
parent
6b21db0dd9
commit
ca61ee4ac2
2 changed files with 34 additions and 0 deletions
24
c-daemon/daemon.c
Normal file
24
c-daemon/daemon.c
Normal 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
10
c-daemon/test.c
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int _daemon (int, int);
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
getchar();
|
||||||
|
_daemon(0, 0);
|
||||||
|
getchar();
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in a new issue