54 lines
1.3 KiB
Groff
54 lines
1.3 KiB
Groff
'\"macro stdmacro
|
|
.TH DAEMONIZE 3 "7 March 1991"
|
|
.IX daemonize#(3) "" "\fLdaemonize\fP(3) \(em \*(Sd make a daemon"
|
|
.SH NAME
|
|
_daemonize \- make a process into a daemon
|
|
.SH SYNOPSIS
|
|
.B "#include <unistd.h>"
|
|
.sp
|
|
.B "int _daemonize(int flags, int fd1, int fd2, int fd3);"
|
|
.SH DESCRIPTION
|
|
The
|
|
.I _daemonize
|
|
function does the common work needed ``to put a function into the
|
|
background,'' or to make it into a ``daemon.''
|
|
That generally includes forking a new process,
|
|
closing most files, and releasing the controlling tty.
|
|
.PP
|
|
If
|
|
.B "flags & _DF_NOFORK"
|
|
is 0, then a new process in a new session is started.
|
|
Debugging is often easier with
|
|
.B flags
|
|
set to contain
|
|
.BR _DF_NOFORK .
|
|
.PP
|
|
If
|
|
.B "flags & _DF_NOCHDIR"
|
|
is 0, then the current working directory is changed to /.
|
|
Otherwise, the current working directory is unchanged.
|
|
.PP
|
|
If
|
|
.B "flags & _DF_NOCLOSE"
|
|
is 0, then all file descriptors except
|
|
.BR fd1 ,
|
|
.BR fd2 ,
|
|
and
|
|
.B fd3
|
|
are closed.
|
|
Because
|
|
.I _daemonize
|
|
closes all file descriptors,
|
|
.IR closelog()
|
|
is called to stop logging cleanly.
|
|
The
|
|
.BI fd #
|
|
arguments should be -1 if they are not file descriptors to be left open.
|
|
.SH "SEE ALSO"
|
|
close(2), chdir(2), fork(2), getdtablesize(2), syslog(3B), setsid(2),
|
|
tty(1), tty(7)
|
|
.SH DIAGNOSTICS
|
|
The returned value \-1 indicates that one of the necessary system
|
|
calls failed.
|
|
.TE
|