Run a process in the background
#include <stdlib.h> int daemon( int nochdir, int noclose );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The daemon() function allows programs to detach themselves from the controlling terminal and run in the background as system daemons.
This function calls fork() and setsid().
If daemon() is called with a noclose value of 0 and fails, then the state of file descriptors 0, 1, and 2 (STDIN_FILENO, STDOUT_FILENO, and STDERR_FILENO) is undefined.
The High Availability Manager can see death messages only from self-attached entities, processes that terminate abnormally, and tasks that are running in session 1. The daemon() function doesn't put the caller into that session; either make your process into a self-attached entity, or use procmgr_daemon() instead if you want to use your application with the HAM.
The HAM automatically switches to monitoring the new process that daemon() creates, if the original process was a self-attached entity. For more information, see the High Availability Framework Developer's Guide.
Zero for success, or -1 if an error occurs (errno is set).
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |