daemon man page on OpenIndiana

Man page or keyword search:  
man Server   20441 pages
apropos Keyword Search (all sections)
Output format
OpenIndiana logo
[printable version]

daemon(3C)		 Standard C Library Functions		    daemon(3C)

NAME
       daemon - basic daemonization function

SYNOPSIS
       #include <stdlib.h>

       int daemon(int nochdir, int noclose);

DESCRIPTION
       The  daemon()  function provides a means for applications to run in the
       background.

       This function ensures that the process calling this function:

	   o	  runs in the background

	   o	  detaches from the controlling terminal

	   o	  forms a new process group

	   o	  is not a session group leader.

       The arguments to this function are treated as boolean variables and are
       evaluated using negative logic.

       If  the	nochdir argument is zero the working directory will be changed
       to the root directory (/); otherwise it will not be.

       If the noclose 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 /dev/null; otherwise  they  will
       not be.

RETURN VALUES
       Upon successful completion, daemon() returns 0. Otherwise it returns -1
       and sets errno to the values specified for fork(2), setsid(2), open(2),
       and dup(2).

       If  daemon()  is	 called	 with  noclose	set to 0 and fails to redirect
       descriptors 0, 1, and 2 to /dev/null, those descriptors are not guaran‐
       teed to be the same as before the call.

EXAMPLES
       Example 1 Using daemon to run a process in the background.

       The main() function of a network server could look like this:

	 int background;     /* background flag */

	 /* Load and verify the configuration. */

	 /* Go into background. */
	 if (background && daemon(0, 0) < 0)
		 err(1, "daemon");

	 /* Process requests here. */

ATTRIBUTES
       See attributes(5) for descriptions of the following attributes:

       ┌─────────────────────────────┬─────────────────────────────┐
       │      ATTRIBUTE TYPE	     │	    ATTRIBUTE VALUE	   │
       ├─────────────────────────────┼─────────────────────────────┤
       │Interface Stability	     │Committed			   │
       ├─────────────────────────────┼─────────────────────────────┤
       │MT-Level		     │Async-Signal-Safe		   │
       └─────────────────────────────┴─────────────────────────────┘

SEE ALSO
       Intro(2), dup(2), fork(2), open(2), setsid(2), attributes(5)

SunOS 5.11			  15 Sep 2009			    daemon(3C)
[top]

List of man pages available for OpenIndiana

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Tweet
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
....................................................................
Vote for polarhome
Free Shell Accounts :: the biggest list on the net