protected function shutdown($restart = false)
    {
        // If we are already exiting, chill.
        if ($this->exiting) {
            return;
        } else // If not, now we are.
        {
            $this->exiting = true;
        }

        // If we aren't already daemonized then just kill the application.
        if (!$this->running && !$this->isActive()) {
            $this->getLogger()->info('Process was not daemonized yet, just halting current process');

            $this->close();
        }

        // Only read the pid for the parent file.
        if ($this->parentId == $this->processId) {
            // Read the contents of the process id file as an integer.
            $fp = fopen($this->config->get('application_pid_file'), 'r');
            $pid = fread($fp, filesize($this->config->get('application_pid_file')));
            $pid = (int) $pid;
            fclose($fp);

            // Remove the process id file.
            @ unlink($this->config->get('application_pid_file'));

            // If we are supposed to restart the daemon we need to execute the same command.
            if ($restart) {
                $this->close(exec(implode(' ', $GLOBALS['argv']) . ' > /dev/null &'));
            } else // If we are not supposed to restart the daemon let's just kill -9.
            {
                passthru('kill -9 ' . $pid);
                $this->close();
            }
        }
    }