use unistd.h daemon function
This commit is contained in:
+32
-1
@@ -48,7 +48,7 @@ void close_lock_file()
|
|||||||
remove(LOCK_FILE);
|
remove(LOCK_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void daemonize(){
|
void kamathvasudev_daemonize(){
|
||||||
int pid;
|
int pid;
|
||||||
int i;
|
int i;
|
||||||
char str[10];
|
char str[10];
|
||||||
@@ -85,3 +85,34 @@ void daemonize(){
|
|||||||
|
|
||||||
atexit(close_lock_file);
|
atexit(close_lock_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void daemonize()
|
||||||
|
{
|
||||||
|
pid_t pid;
|
||||||
|
char str[10];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* use unistd.h function
|
||||||
|
* - do change to root directory
|
||||||
|
* - close std streams
|
||||||
|
*/
|
||||||
|
daemon(1, 0);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Double fork method
|
||||||
|
*/
|
||||||
|
pid = fork();
|
||||||
|
if(pid < 0) exit(1);
|
||||||
|
if(pid > 0) exit(0);
|
||||||
|
|
||||||
|
umask(022);
|
||||||
|
|
||||||
|
lfp = open(LOCK_FILE,O_RDWR|O_CREAT,0640);
|
||||||
|
if(lfp < 0) { log_signal_message("daemond is allready running !\n");exit(1); }
|
||||||
|
if(lockf(lfp,F_TLOCK,0) < 0) { log_signal_message("daemond is allready running\n");exit(1); }
|
||||||
|
|
||||||
|
sprintf(str,"%d\n",getpid());
|
||||||
|
write(lfp,str,strlen(str));
|
||||||
|
|
||||||
|
atexit(close_lock_file);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
process 11096 signal 15 trapped
|
process 11096 signal 15 trapped
|
||||||
|
process 16565 signal 15 trapped
|
||||||
|
|||||||
Reference in New Issue
Block a user