}
} else {
    flock($pidFp, LOCK_EX | LOCK_NB);
}
// PID file IS locked after that point
/**
 * Signal handler for the daemon process
 * @param int $signo Signal number
 */
$daemonSignalHandler = function ($signo) use($pidFp, $pidFile) {
    switch ($signo) {
        case SIGTERM:
        case SIGINT:
            flock($pidFp, LOCK_UN);
            fclose($pidFp);
            ezpContentPublishingQueueProcessor::terminate();
            @unlink($pidFile);
            eZScript::instance()->shutdown(0);
            break;
    }
};
pcntl_signal(SIGTERM, $daemonSignalHandler);
pcntl_signal(SIGINT, $daemonSignalHandler);
if ($options['daemon']) {
    // Trap signals that we expect to recieve
    pcntl_signal(SIGCHLD, 'childHandler');
    pcntl_signal(SIGUSR1, 'childHandler');
    pcntl_signal(SIGALRM, 'childHandler');
    // close the PID file, and reopen it after forking
    fclose($pidFp);
    eZClusterFileHandler::preFork();
/**
 * Signal handler for the daemon process
 * @param int $signo Signal number
 */
function daemonSignalHandler($signo)
{
    switch ($signo) {
        case SIGTERM:
        case SIGINT:
            flock($GLOBALS['pidFp'], LOCK_UN);
            fclose($GLOBALS['pidFp']);
            ezpContentPublishingQueueProcessor::terminate();
            @unlink($GLOBALS['pidFile']);
            eZScript::instance()->shutdown(0);
            break;
    }
}