procmgr_daemon()

Updated: April 19, 2023

Run a process in the background

Synopsis:

#include <sys/procmgr.h>

int procmgr_daemon( int status,
                    unsigned flags );

Arguments:

status
The status that you want to return to the parent process.
flags
The flags currently defined (in <sys/procmgr.h>) are:
  • PROCMGR_DAEMON_NOCHDIR — unless this flag is set, procmgr_daemon() changes the current working directory to the root /.
  • PROCMGR_DAEMON_NOCLOSE — unless this flag is set, procmgr_daemon() closes all file descriptors other than standard input, standard output and standard error.
  • PROCMGR_DAEMON_NODEVNULL — unless this flag is set, procmgr_daemon() redirects standard input, standard output and standard error to /dev/null.
  • PROCMGR_DAEMON_KEEPUMASK — unless this flag is set, procmgr_daemon() sets the umask to 0 (zero).

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The procmgr_daemon() function lets programs detach themselves from the controlling terminal and run in the background as system daemons. This also puts the caller into session 1.

If procmgr_daemon() is called without PROCMGR_DAEMON_NOCLOSE set in flags and fails, then the state of file descriptors 0, 1, and 2 (STDIN_FILENO, STDOUT_FILENO, and STDERR_FILENO) is undefined.

The argument status is returned to the parent process as if exit() were called; the returned value is normally EXIT_SUCCESS.

Note: The data in the siginfo_t structure for the SIGCHLD signal that the parent receives isn't useful in this case.

Returns:

A nonnegative integer, or -1 if an error occurs (errno is set).

Classification:

QNX Neutrino

Safety:  
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes