daemon()

NAME

daemon() - run in the background

SYNOPSIS

#include <stdlib.h>

int daemon (int nochdir, int noclose)

DESCRIPTION

The daemon(3) call is an interface to allow a program to become a system daemon. The function causes the calling program to fork(2); the parent exits and the child then performs a setsid(2). This disassociates the process from its current process group, session, and controlling terminal. On successful completion of this call, the process is the session leader of a group in which it is the only member, and the session has no controlling terminal.

If nochdir is zero, the process changes its current working directory to the installed root of INTERIX. Otherwise the current working directory is unchanged.

If noclose is zero, the process redirects standard input, standard output, and standard error to /dev/null. Otherwise the standard file handles remain directed at the terminal that was previously the controlling terminal.

RETURN VALUES

The daemon(3) function returns 0 on success; on failure, it returns -1 and sets the global variable errno.

ERRORS

The daemon(3) function can fail for the following reasons:

[EAGAIN]
The system-imposed limit on the total number of processes under execution would be exceeded. This limit is configuration-dependent.
[EAGAIN]
The system-imposed limit on the total number of processes under execution by a single user would be exceeded.
[EPERM]
The calling process is already a process group leader, or the process group ID of a process other than the calling process matches the process ID of the calling process.

SEE ALSO

fork(2)

setsid(2)