dfork.h(3)
πΈ dfork.h β NAME πΈ
okay so bestie, gather round π dfork.h is the header that hands you a whole entire API for doing a daemonizing fork(). that's the whole vibe. it's giving "spawn a background process, but make it correct and make it slay" π
β¨ SYNOPSIS β¨
#include <sys/types.h>
π Macros
#define DAEMON_CLOSE_ALL_AVAILABLE 1β this macro is defined to1iffdaemon_close_all()anddaemon_close_allv()are supported. literally the "do you have this feature" check π#define DAEMON_UNBLOCK_SIGS_AVAILABLE 1β defined to1iffdaemon_unblock_sigs()anddaemon_unblock_sigsv()are supported.#define DAEMON_RESET_SIGS_AVAILABLE 1β defined to1iffdaemon_reset_sigs()anddaemon_reset_sigsv()are supported.
π¦ Functions
pid_t daemon_fork (void)β does a daemonizingfork(). the main character of this whole header fr fr.int daemon_retval_init (void)β allocate and initialize the resources that thedaemon_retval_xxx()functions need.void daemon_retval_done (void)β frees the resources thatdaemon_retval_init()allocated. cleanup era π§Ήint daemon_retval_wait (int timeout)β return the value the child sent viadaemon_retval_send(), but only wait the specified number of seconds before it times out and returns a negative number.int daemon_retval_send (int s)β send the specified integer to the parent process.int daemon_close_all (int except_fd,...)β close all file descriptors except the ones you passed.int daemon_close_allv (const int except_fds[])β same asdaemon_close_allbut it takes an array of fds, terminated by-1.int daemon_unblock_sigs (int except,...)β unblock all signals except the ones you passed.int daemon_unblock_sigsv (const int except[])β same asdaemon_unblock_sigs()but it takes an array of signals, terminated by-1.int daemon_reset_sigs (int except,...)β reset all signal handlers except the ones you passed.int daemon_reset_sigsv (const int except[])β same asdaemon_reset_sigs()but it takes an array of signals, terminated by-1.
π Detailed Description
contains an API for doing a daemonizing fork(). yes that's the sentence, and yes it's iconic.
you may daemonize by calling daemon_fork(), a function similar to the plain fork(). and 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. that's the whole plot π
Definition in file dfork.h.
π Macro Definition Documentation
#define DAEMON_CLOSE_ALL_AVAILABLE 1
this variable is defined to 1 iff daemon_close_all() and daemon_close_allv() are supported. no cap.
Since
0.11
See also
daemon_close_all(), daemon_close_allv()
Definition at line 106 of file dfork.h.
#define DAEMON_RESET_SIGS_AVAILABLE 1
this variable is defined to 1 iff daemon_reset_sigs() and daemon_reset_sigsv() are supported. π«Ά
Since
0.13
See also
daemon_reset_sigs(), daemon_reset_sigsv()
Definition at line 142 of file dfork.h.
#define DAEMON_UNBLOCK_SIGS_AVAILABLE 1
this variable is defined to 1 iff daemon_unblock_sigs() and daemon_unblock_sigsv() are supported. π«
Since
0.13
See also
daemon_unblock_sigs(), daemon_unblock_sigsv()
Definition at line 124 of file dfork.h.
π₯ Function Documentation
int daemon_close_all (int except_fd, ...)
close all file descriptors except the ones passed. the list needs to be terminated by -1. and heads up β FDs 0, 1, 2 will be kept open anyway, always, no matter what you say. they're not like other fds π
Since
0.11
See also
DAEMON_CLOSE_ALL_AVAILABLE
Examples
testd.c.
int daemon_close_allv (const int except_fds[])
same as daemon_close_all but takes an array of fds, terminated by -1.
Since
0.11
See also
DAEMON_CLOSE_ALL_AVAILABLE
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 /, and the umask is set to 777. she's fully self-sufficient, she's moved out, she's got her own place π β¨
Returns
on success, the PID of the child process is returned in the parent's thread of execution, and a 0 is returned in the child's thread of execution. on failure, -1 will be returned in the parent's context, no child process will be created, and errno will be set appropriately. so like. check your errno, bestie π
Examples
testd.c.
int daemon_reset_sigs (int except, ...)
reset all signal handlers except those passed. list needs to be terminated by -1.
Since
0.13
See also
DAEMON_RESET_SIGS_AVAILABLE
Examples
testd.c.
int daemon_reset_sigsv (const int except[])
same as daemon_reset_sigs() but takes an array of signals, terminated by -1.
Since
0.13
See also
DAEMON_RESET_SIGS_AVAILABLE
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. and listen β the resources allocated by daemon_retval_init() should be freed in both the parent and the daemon process. you can achieve that by using daemon_retval_wait() resp. daemon_retval_send(), or by using daemon_retval_done(). it's giving "two ways to leave the party, but you DO have to leave" π
Examples
testd.c.
int daemon_retval_init (void)
allocate and initialize the resources required by the daemon_retval_xxx() functions. these functions let the child send a value to the parent after completing its initialisation. call this in the parent before forking. order matters, bestie π
Returns
zero on success, nonzero on failure.
Examples
testd.c.
int daemon_retval_send (int s)
send the specified integer to the parent process. do not send -1 because this signifies a library error π¨ (like, the library reserves that value, so sending it is you breaking the contract). 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)
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.
Parameters
timeout β the timeout in seconds
Returns
the integer passed to daemon_retval_send() in the daemon process, or -1 on failure.
Examples
testd.c.
int daemon_unblock_sigs (int except, ...)
unblock all signals except those passed. list needs to be terminated by -1. let them through, girl, except the ones you're specifically holding back π¦
Since
0.13
See also
DAEMON_UNBLOCK_SIGS_AVAILABLE
Examples
testd.c.
int daemon_unblock_sigsv (const int except[])
same as daemon_unblock_sigs() but takes an array of signals, terminated by -1.
Since
0.13
See also
DAEMON_UNBLOCK_SIGS_AVAILABLE
π Author
generated automatically by Doxygen for libdaemon from the source code. the robot wrote it, I just gave it a personality π
and that's the whole page, bestie π«Ά this is dfork.h(3), part of libdaemon, Version 0.14, and it was generated by Doxygen for libdaemon straight from the source code. go forth and daemonize responsibly, mwah π
β¨πΈ
π¦ where this page comes from
- ubuntu noble: libdaemon-doc 0.14-7.1ubuntu4
- ubuntu questing: libdaemon-doc 0.14-7.1ubuntu4
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms