#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) |
Allocate and initialize resources required by the daemon_retval_xxx() functions. | |
void | daemon_retval_done (void) |
Frees the resources allocated by daemon_retval_init(). | |
int | daemon_retval_wait (int timeout) |
Return the value sent by the child via the daemon_retval_send() function, but wait only the specified number of seconds before timing out and returning a negative number. | |
int | daemon_retval_send (int s) |
Send the specified integer to the parent process. |
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.
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.
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 called in the current process. The resources allocated by daemon_retval_init() should be freed in both parent and daemon process. This may be achieved by using daemon_retval_wait() resp. daemon_retval_send(), or by using daemon_retval_done().
int daemon_retval_init | ( | void | ) |
Allocate and initialize resources required by the daemon_retval_xxx() functions.
These functions allow the child to send a value to the parent after completing its initialisation. Call this in the parent before forking.
int daemon_retval_send | ( | int | s | ) |
Send the specified integer to the parent process.
Do not send -1 because this signifies a library error. Should be called just once from the daemon process only. A subsequent call to daemon_retval_done() in the daemon is ignored.
s | The integer to pass to daemon_retval_wait() in the parent process |
int daemon_retval_wait | ( | int | timeout | ) |
Return the value sent by the child via the daemon_retval_send() function, but wait only the specified number of seconds before timing out and returning a negative number.
Should be called just once from the parent process only. A subsequent call to daemon_retval_done() in the parent is ignored.
timeout | Thetimeout in seconds |