PIDFILE(3) BSD Library Functions Manual PIDFILE(3)NAMEpidfile — write a daemon pid file
LIBRARY
System Utilities Library (libutil, -lutil)
SYNOPSIS
#include <sys/types.h>
#include <libutil.h>
int
pidfile(const char *basename);
DESCRIPTIONpidfile() 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.
Note that only the first invocation of pidfile causes a pid file to be
written; subsequent invocations have no effect unless a new basename is
supplied. If called with a new basename, pidfile() will remove the old
pid file and write the new one.
RETURN VALUESpidfile() returns 0 on success and -1 on failure.
SEE ALSOatexit(3)HISTORY
The pidfile function call appeared in NetBSD 1.5.
BUGSpidfile() uses atexit(3) to ensure the pidfile is unlinked at program
exit. However, programs that use the _exit(2) function (for example, in
signal handlers) will not trigger this behaviour.
BSD June 5, 1999 BSD