Run Daemon in linux
Posted 01-13-2006 at 07:20 AM by bogoda
HI ,
I am new to Red Hat 9.
I want to know how can i create a Deamon program to run in linux when system boot up.
I run the following program.
But no out put.
I want set it as Daemon.
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <syslog.h>
#include <string.h>
int main(void) {
/* Our process ID and Session ID */
pid_t pid, sid;
/* Fork off the parent process */
pid = fork();
if (pid < 0) {
exit(EXIT_FAILURE);
}
/* Close out the standard file descriptors */
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
/* Daemon-specific initialization goes here */
/* The Big Loop */
while (1) {
printf("Inside Enter j:");
/* Do some task here ... */
sleep(100); /* wait 30 seconds */
}
//exit(EXIT_SUCCESS);
}
Any one kow the solution plse.
Thank you.
I am new to Red Hat 9.
I want to know how can i create a Deamon program to run in linux when system boot up.
I run the following program.
But no out put.
I want set it as Daemon.
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <syslog.h>
#include <string.h>
int main(void) {
/* Our process ID and Session ID */
pid_t pid, sid;
/* Fork off the parent process */
pid = fork();
if (pid < 0) {
exit(EXIT_FAILURE);
}
/* Close out the standard file descriptors */
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
/* Daemon-specific initialization goes here */
/* The Big Loop */
while (1) {
printf("Inside Enter j:");
/* Do some task here ... */
sleep(100); /* wait 30 seconds */
}
//exit(EXIT_SUCCESS);
}
Any one kow the solution plse.
Thank you.
Total Comments 2
Comments
-
If any one know this.
Posted 12-31-1969 at 07:00 PM by bogoda
-
This(as well as the post above this) should be posted in the forums.Posted 12-31-1969 at 07:00 PM by bogoda




