Kea 3.1.3
isc::util::PIDFile Class Reference

Class to help with processing PID files. More...

#include <pid_file.h>

Public Member Functions

 PIDFile (const std::string &filename)
 Constructor.
 
virtual ~PIDFile ()=default
 Destructor.
 
int check () const
 Read the PID in from the file and check it.
 
void deleteFile () const
 Delete the PID file.
 
std::string getFilename () const
 Returns the path to the PID file.
 
std::string getLockname () const
 Returns the path to the lock file.
 
void write () const
 Get PID of the current process and write it to the file.
 
void write (int) const
 Write the PID to the file.
 

Detailed Description

Class to help with processing PID files.

This is a utility class to manipulate PID file. It provides functions for writing and deleting a file containing a PID as well as for extracting a PID from a file and checking if the process is still running.

Definition at line 40 of file pid_file.h.

Constructor & Destructor Documentation

◆ PIDFile()

isc::util::PIDFile::PIDFile ( const std::string & filename)
inline

Constructor.

Parameters
filenamePID filename.

Definition at line 45 of file pid_file.h.

◆ ~PIDFile()

virtual isc::util::PIDFile::~PIDFile ( )
virtualdefault

Destructor.

Member Function Documentation

◆ check()

int isc::util::PIDFile::check ( ) const

Read the PID in from the file and check it.

Read the PID in from the file then use it to see if a process with that PID exists. If the file doesn't exist treat it as the process not being there. If the file exists but can't be read or it doesn't have the proper format treat it as the process existing.

The PID file should be locked to avoid a race condition.

Returns
returns the PID if it is in, 0 otherwise.
Exceptions
throwsPIDCantReadPID if it was able to open the file but was unable to read the PID from it.

Definition at line 23 of file pid_file.cc.

References isc_throw.

Referenced by isc::dhcp::LFCSetup::execute(), isc::dhcp::Memfile_LeaseMgr::isLFCProcessRunning(), and isc::lfc::LFCController::launch().

◆ deleteFile()

void isc::util::PIDFile::deleteFile ( ) const

Delete the PID file.

This is an atomic operation not subject to a race condition.

Exceptions
throwsPIDFileError if it can't delete the PID file

Definition at line 81 of file pid_file.cc.

References isc_throw.

Referenced by isc::dhcp::LFCSetup::execute(), and isc::lfc::LFCController::launch().

◆ getFilename()

std::string isc::util::PIDFile::getFilename ( ) const
inline

Returns the path to the PID file.

Definition at line 92 of file pid_file.h.

◆ getLockname()

std::string isc::util::PIDFile::getLockname ( ) const
inline

Returns the path to the lock file.

Definition at line 97 of file pid_file.h.

Referenced by isc::dhcp::LFCSetup::execute(), isc::dhcp::Memfile_LeaseMgr::isLFCProcessRunning(), and isc::lfc::LFCController::launch().

◆ write() [1/2]

void isc::util::PIDFile::write ( ) const

Get PID of the current process and write it to the file.

The PID file must be locked to avoid a race condition.

Exceptions
throwsPIDFileError if it can't open or write to the PID file.

Definition at line 55 of file pid_file.cc.

References write().

Referenced by write().

+ Here is the call graph for this function:

◆ write() [2/2]

void isc::util::PIDFile::write ( int pid) const

Write the PID to the file.

The PID file must be locked to avoid a race condition.

Parameters
pidthe pid to write to the file.
Exceptions
throwsPIDFileError if it can't open or write to the PID file.

Definition at line 60 of file pid_file.cc.

References isc_throw.

Referenced by isc::dhcp::LFCSetup::execute(), and isc::lfc::LFCController::launch().


The documentation for this class was generated from the following files: