Cheers // Fredrik Roubert
--
M?llev?ngsv?gen 6c | +46 46 188127
SE-222 40 Lund | http://www.df.lth.se/~roubert/
-- ced
--
Chuck Dillon
Senior Software Engineer
NimbleGen Systems Inc.
Here's a function that daemonises a process.
Duke
/*
* int daemonise()
*
* This function creates a child of the the current process
* and turns it into a daemon using setsid(). The current
* process dies in here.
*
*/
#include <sys/file.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <unistd.h>
int daemonise()
{
int num_files;
int fd;
pid_t pgid;
int cur_file;
/* become a child; parent dies */
pid= fork();
if (pid == -1) {
/* error */
return(1);
} else if (pid > 0) {
/* this is the parent. die */
exit(0);
} else {
/* this is the child, do your thing */
/* create a new session and become session leader. */
/* This gets rid of the controlling terminal, too */
pgid= setsid();
if (pgid==-1) {
/* error */
return(2);
}
/* back before setsid(), you use to do this to */
/* get rid of the controlling terminal */
// if (fd= open("/dev/tty", O_RDWR|O_NOCTTY) >= 0) {
// ioctl(fd, TIOCNOTTY, 0);
// (void) close(fd);
// } else {
// return(2);
// }
/* close all file descriptors */
num_files= getdtablesize();
for (cur_file = 0; cur_file < num_files; cur_file++)
(void) close(cur_file);
/* attach file descriptors 0,1,2 to /dev/null */
(void) open("/dev/null", O_RDONLY);
(void) open("/dev/null", O_WRONLY);
(void) dup(1);
}
/* that's it, we're a daemon. Pretty cool, huh? */
return(0);
Quote:}
1. Sherlock linux plug-ins / sherlock for linux?
2. Setting up Ghostscript in printcap?
3. ATT: Server Daemons: IRC server daemon for Linux?
4. modem and sound, something different...
5. List of plug-ins for linux/netscape please!
7. Errors compiling Wingz 1.4 Add-ins (Linux 1.3.99, GCC 2.6)
8. FVWM-XPM
10. netscape-i686-pc-linux-gnu-ins
11. Netscape plug-ins under Linux
12. how to use plug-ins in navigator-linux?
13. Ich m?chte eine Verbindung ins Internet Linux und einer TelesS0 16.3