Main Page   File List   Globals   Examples  

dfork.h File Reference

Contains an API for doing a daemonizing fork(). More...

#include <sys/types.h>

Go to the source code of this file.

Functions

pid_t daemon_fork (void)
 Does a daemonizing fork().

int daemon_retval_init (void)
 Initializes the library for allowing the passing of a return value from the daemon initialization to the parent process.

void daemon_retval_done (void)
 Frees the resources allocated by daemon_retval_init().

int daemon_retval_wait (int timeout)
 Wait the specified amount of seconds for the response of the daemon process and return the integer passed to daemon_retval_send() in the daemon process.

int daemon_retval_send (int s)
 Send the specified integer to the parent process.


Detailed Description

Contains an API for doing a daemonizing fork().

You may daemonize by calling daemon_fork(), a function similar to the plain fork(). If you want to return a return value of the initialization procedure of the child from the parent, you may use the daemon_retval_xxx() functions.

Definition in file dfork.h.


Function Documentation

pid_t daemon_fork void   
 

Does a daemonizing fork().

For the new daemon process STDIN, STDOUT, STDERR are connected to /dev/null, the process is a session leader, the current directory is changed to /, the umask is set to 777.

Returns:
zero on success in the child, the PID of the new daemon process in the parent, nonzero on failure
Examples:
testd.c.

void daemon_retval_done void   
 

Frees the resources allocated by daemon_retval_init().

This should be called if neither daemon_retval_wait() nor daemon_retval_send() is used. If a fork took place, the function should be called in both the parent and the daemon.

Examples:
testd.c.

int daemon_retval_init void   
 

Initializes the library for allowing the passing of a return value from the daemon initialization to the parent process.

Call this before calling any of the other daemon_retval_xxx() functions in the parent, before forking.

Returns:
zero on success, nonzero on failure.
Examples:
testd.c.

int daemon_retval_send int    s
 

Send the specified integer to the parent process.

Should be called just once from the daemon process only. A subsequent call to daemon_retval_done() in the daemon is ignored.

Parameters:
s  The integer to pass to daemon_retval_wait() in the parent process
Returns:
Zero on success, nonzero on failure.
Examples:
testd.c.

int daemon_retval_wait int    timeout
 

Wait the specified amount of seconds for the response of the daemon process and return the integer passed to daemon_retval_send() in the daemon process.

Should be called just once from the parent process only. A subsequent call to daemon_retval_done() in the parent is ignored.

Parameters:
timeout  The timeout in seconds
Returns:
The integer passed daemon_retval_send() in the daemon process, or negative on failure.
Examples:
testd.c.


Generated on Thu Jul 10 19:49:51 2003 for libdaemon by doxygen1.2.18