public function getPid(): int
    {
        $pid_file = $this->config->getPidFile();
        if (!file_exists($pid_file)) {
            $msg = "Pid file cannot be found '$pid_file'";
            $this->logger->info("Get PID failed: $msg");
            throw new Exception\PidNotFoundException($msg);
        }
        $pid = trim(file_get_contents($pid_file));
        if (!preg_match('/^[0-9]+$/', $pid)) {
            $msg = "Pid found '$pid_file' but no valid pid stored in it or corrupted file '$pid_file'.";
            $this->logger->error("Get PID failed: $msg");
            throw new Exception\PidCorruptedException($msg);
        }

        return (int) $pid;
    }