Click to See Complete Forum and Search --> : Can I run anything as a daemon?


nanode
03-06-2001, 09:54 PM
I have a basic understanding of what daemons are and how the work with the whole system.

What is necessary to make a simple application run as a daemon? If I wrote a simple socket program that ran in console, could I easily run that as a daemon?

I'll accept good links on this topic.

Thanks.

osnap
03-06-2001, 09:58 PM
I found a little program that lets you run anything as a daemon. I don't know where I found it but I still have the source on my linux box and I'll email it to you later if you want.

bdg1983
03-06-2001, 11:53 PM
Either that, or I can cut and paste some code in here that I used to make something a daemon:

// Daemon stuff
pid = fork();
if(pid < 0) {
perror("fork");
puts("insultd did not start\n");
exit(EXIT_FAILURE);
}

if(pid > 0)
exit(EXIT_SUCCESS); //Parent suicides. We barely knew ye...

// Now on to the child...

if((sid=setsid()) < 0) {
perror("setsid");
exit(EXIT_FAILURE);
}

if((chdir("/")) < 0) {
perror("chdir");
exit(EXIT_FAILURE);
}

umask(0);
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);


[ 06 March 2001: Message edited by: bdg1983 ]

nanode
03-07-2001, 11:14 AM
Hey thanks. I'll play with that.