Removes the PID file if it exists and cleans up the exit handler.
Writes the current process PID to the PID file and sets up a handler to remove the PID file on process exit.
Note: If the process crashes or is forcefully terminated, the PID file may not be removed. In such cases, manual cleanup may be necessary.
This method ensures that the directory for the PID file exists before writing the file.
Class to manage a PID file for the current process.
This class provides methods to write the current process PID to a specified file and to remove the PID file when it is no longer needed.
Note: The PID file is automatically removed when the process exits, if it was created by this class instance.
Example usage: