daemon -- run in the background


#include <unistd.h>

int daemon(int nochdir, int noclose);


The daemon() function shall create a new process, detached from the controlling terminal. If successful, the calling process shall exit and the new process shall continue to execute the application in the background. If nochdir evaluates to true, the current directory shall not be changed. Otherwise, daemon() shall change the current working directory to the root (`/'). If noclose evaluates to true the standard input, standard output, and standard error file descriptors shall not be altered. Otherwise, daemon() shall close the standard input, standard output and standard error file descriptors and reopen them attached to /dev/null.

Return Value

On error, -1 is returned, and the global variable errno is set to any of the errors specified for the library functions fork() and setsid().