summaryrefslogtreecommitdiff
path: root/usr/src/man/man3c/daemon.3c
diff options
context:
space:
mode:
authorRichard Lowe <richlowe@richlowe.net>2011-03-14 14:05:30 -0400
committerRichard Lowe <richlowe@richlowe.net>2011-03-14 14:05:30 -0400
commitc10c16dec587a0662068f6e2991c29ed3a9db943 (patch)
treef414286f4bba41d75683ed4fbbaa6bfa4bf7fabd /usr/src/man/man3c/daemon.3c
parent68caef18a23a498d9e3017b983562c0f4fd8ab23 (diff)
downloadillumos-gate-c10c16dec587a0662068f6e2991c29ed3a9db943.tar.gz
243 system manual pages should live with the software
Reviewed by: garrett@nexenta.com Reviewed by: gwr@nexenta.com Reviewed by: trisk@opensolaris.org Approved by: gwr@nexenta.com --HG-- extra : rebase_source : 0c599d0bec0dc8865fbba67721a7a6cd6b1feefb
Diffstat (limited to 'usr/src/man/man3c/daemon.3c')
-rw-r--r--usr/src/man/man3c/daemon.3c118
1 files changed, 118 insertions, 0 deletions
diff --git a/usr/src/man/man3c/daemon.3c b/usr/src/man/man3c/daemon.3c
new file mode 100644
index 0000000000..b82c45b9d6
--- /dev/null
+++ b/usr/src/man/man3c/daemon.3c
@@ -0,0 +1,118 @@
+'\" te
+.\" Copyright (c) 2009, Sun Microsystems Inc. All Rights Reserved.
+.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.
+.\" See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with
+.\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
+.TH daemon 3C "15 Sep 2009" "SunOS 5.11" "Standard C Library Functions"
+.SH NAME
+daemon \- basic daemonization function
+.SH SYNOPSIS
+.LP
+.nf
+#include <stdlib.h>
+
+\fBint\fR \fBdaemon\fR(\fBint\fR \fInochdir\fR, \fBint\fR \fInoclose\fR);
+.fi
+
+.SH DESCRIPTION
+.sp
+.LP
+The \fBdaemon()\fR function provides a means for applications to run in the
+background.
+.sp
+.LP
+This function ensures that the process calling this function:
+.RS +4
+.TP
+.ie t \(bu
+.el o
+runs in the background
+.RE
+.RS +4
+.TP
+.ie t \(bu
+.el o
+detaches from the controlling terminal
+.RE
+.RS +4
+.TP
+.ie t \(bu
+.el o
+forms a new process group
+.RE
+.RS +4
+.TP
+.ie t \(bu
+.el o
+is not a session group leader.
+.RE
+.sp
+.LP
+The arguments to this function are treated as boolean variables and are
+evaluated using negative logic.
+.sp
+.LP
+If the \fInochdir\fR argument is zero the working directory will be changed to
+the root directory (/); otherwise it will not be.
+.sp
+.LP
+If the \fInoclose\fR argument is zero the descriptors 0, 1, and 2 (normally
+corresponding to standard input, output and error output, depending on the
+application) will be redirected to \fB/dev/null\fR; otherwise they will not be.
+.SH RETURN VALUES
+.sp
+.LP
+Upon successful completion, \fBdaemon()\fR returns 0. Otherwise it returns -1
+and sets \fBerrno\fR to the values specified for \fBfork\fR(2),
+\fBsetsid\fR(2), \fBopen\fR(2), and \fBdup\fR(2).
+.sp
+.LP
+If \fBdaemon()\fR is called with \fInoclose\fR set to 0 and fails to redirect
+descriptors 0, 1, and 2 to \fB/dev/null\fR, those descriptors are not
+guaranteed to be the same as before the call.
+.SH EXAMPLES
+.LP
+\fBExample 1 \fRUsing daemon to run a process in the background.
+.sp
+.LP
+The \fBmain()\fR function of a network server could look like this:
+
+.sp
+.in +2
+.nf
+int background; /* background flag */
+
+/* Load and verify the configuration. */
+
+/* Go into background. */
+if (background && daemon(0, 0) < 0)
+ err(1, "daemon");
+
+/* Process requests here. */
+.fi
+.in -2
+
+.SH ATTRIBUTES
+.sp
+.LP
+See \fBattributes\fR(5) for descriptions of the following attributes:
+.sp
+
+.sp
+.TS
+tab() box;
+cw(2.75i) |cw(2.75i)
+lw(2.75i) |lw(2.75i)
+.
+ATTRIBUTE TYPEATTRIBUTE VALUE
+_
+Interface StabilityCommitted
+_
+MT-LevelAsync-Signal-Safe
+.TE
+
+.SH SEE ALSO
+.sp
+.LP
+\fBIntro\fR(2), \fBdup\fR(2), \fBfork\fR(2), \fBopen\fR(2), \fBsetsid\fR(2),
+\fBattributes\fR(5)