public function startProcess(Process $process, $pidFile, OutputInterface $log)
    {
        $this->processes[$pidFile] = $process;

        try {
            $process->start(function ($type, $buffer) use ($log) {
                $output = $log instanceof ConsoleOutputInterface && $type === Process::ERR
                    ? $log->getErrorOutput()
                    : $log;
                $output->write($buffer);
            });
        } catch (\Exception $e) {
            unset($this->processes[$pidFile]);
            throw $e;
        }

        $pid = $process->getPid();
        if (file_put_contents($pidFile, $pid) === false) {
            throw new \RuntimeException('Failed to write PID file: ' . $pidFile);
        }

        $log->writeln(sprintf('Process started: %s', $process->getCommandLine()));

        return $pid;
    }