OpenBSD manual page server

Manual Page Search Parameters

PIDFILE(3) Library Functions Manual PIDFILE(3)

pidfilewrite a daemon pid file

#include <util.h>

int
pidfile(const char *basename);

() writes a file containing the process ID of the program to the /var/run directory. The file name has the form /var/run/basename.pid. If the basename argument is NULL, pidfile will determine the program name and use that instead.

The pid file can be used as a quick reference if the process needs to be sent a signal. When the program exits, the pid file will be removed automatically, unless the program receives a fatal signal.

pidfile() returns 0 on success and -1 on failure.

atexit(3)

The pidfile function call appeared in OpenBSD 3.0.

If pidfile() is called multiple times with different basename, only the last pidfile will be removed upon exit.

pidfile() uses atexit() to ensure the pidfile is unlinked at program exit. However, programs that use the _exit() function (for example, in signal handlers) will not trigger this behaviour.

June 5, 2013 OpenBSD-6.4