Hi, In package uptimed-0.3.16 the following function is defined: void bg(void) { int i; /* Simple fork to run proces in the background. */ switch(fork()) { case 0: break; case -1: perror("fork failed"); exit(1); default: exit(0); }
if (-1==setsid()) { perror("setsid failed"); exit(1); } /* Close probably all file descriptors */ for (i = 0; i<NOFILE; i++) close(i); /* Be nice to umount */ chdir("/"); } Two questions arrives after discussing with braunr on IRC: 1) Can bg() safely be replaced with daemon()? It is not yet in any posix standard. 2) If not, what to replace NOFILE with in the code for bg()? NOFILE is defined for Linux in /usr/include/sys/param.h but is not recommended: /* The following are not really correct but it is a value we used for a long time and which seems to be usable. People should not use NOFILE and NCARGS anyway. */ #define NOFILE 256 #define NCARGS 131072