@param \Spatie\Async\Process\Runnable|callable $process

@return \Spatie\Async\Process\Runnable
334674
public function add($process): Runnable
    {
        if (! is_callable($process) && ! $process instanceof Runnable) {
            throw new InvalidArgumentException('The process passed to Pool::add should be callable.');
        }

        if (! $process instanceof Runnable) {
            $process = ParentRuntime::createProcess($process);
        }

        $this->putInQueue($process);

        return $process;
    }
1142367
protected function runProcess(Process $process)
    {
        $ioHandler = $this->getIO();
        $process->run(
            function ($pipe, $content) use ($ioHandler) {
                if (Process::ERR === $pipe) {
                    $ioHandler->writeError($content, false);
                    // @codingStandardsIgnoreStart
                    return;
                    // @codingStandardsIgnoreEnd
                }
                $ioHandler->write($content, false);
            }
        );

        if (0 !== $process->getExitCode()) {
            throw new ProcessFailedException($process);
        }
    }
961523
public function execute($command, callable $next)
    {
        if ($command instanceof QueuedCommand && !$command->isRunningInQueue())
        {
            $delay = $command->getDelay() !== null ?: $this->delay;

            $command->setRunningInQueue(true);
            $job = new QueuedJobWrapper([
                'command' => $command,
                'commandBus' => $this->commandBus
            ]);

            return $this->queue->delay($delay)->push($job);
        }

        return $next($command);
    }
1110286
public static function fork($callable)
    {
        if (!is_callable($callable)) {
            throw new \RuntimeException('Callable is not callable.');
        }
        $pid = pcntl_fork();
        if ($pid < 0) {
            throw new \RuntimeException('Unable to fork');
        }

        if ($pid == 0) {
            call_user_func($callable);
            exit;
        }

        $tracker = new PidTracker($pid);

        return $tracker;
    }
1111921
public function runAsync($blocking = self::NON_BLOCKING)
    {
        if ($this->running) {
            throw new RuntimeException('Process already running.');
        }

        try {
            $this->exec(false, $blocking);
        } catch (ProcessException $ex) {
            throw $ex;
        } catch (Exception $ex) {
            $this->cleanup();
            throw new ProcessException('Unknown process exception.', $this, $ex);
        }

        return $this;
    }
127590
public function addChild(Process $process)
    {
        $this->children->set($process->getId(), $process);

        return $this;
    }
1017823
public function getProcessByCommand(string $command) : Process {
        if( ! array_key_exists($command, $this->processes) ) {
            $this->watch($command);
        }

        foreach($this->getWatchedProcesses() as $process) {
            if($process->getCommand() === $command) {
                return $process;
            }
        }
    }
533496
public static function wait(string $args) : ?SymfonyProcess
  {
    $process = new SymfonyProcess('php ' . Accessor::$appRoot . 'craftsman ' . $args);

    $process->start();
    $process->wait();
    $process->stop();

    return $process;
  }
1127741
public function wrapCallback(OutputInterface $output, Process $process, callable $callback = null)
    {
        if ($output instanceof ConsoleOutputInterface) {
            $output = $output->getErrorOutput();
        }

        $formatter = $this->getHelperSet()->get('debug_formatter');

        return function ($type, $buffer) use ($output, $process, $callback, $formatter) {
            $output->write($formatter->progress(spl_object_hash($process), $this->escapeString($buffer), Process::ERR === $type));

            if (null !== $callback) {
                $callback($type, $buffer);
            }
        };
    }
245115
protected function createProcess($interactive = false)
    {
        $process = new Process($this->container->resolve('SHELL'), null, null, null, null, []);

        if ($interactive) {
            $process->setTty(true);
        } else {
            if ($this->container->has('TIMEOUT') && $timeout = $this->container->get('TIMEOUT')) {
                $process->setTimeout($this->container->get('TIMEOUT'));
            }
        }

        return $process;
    }
1365839
protected function execute($command)
    {
        $process = new Process($command);
        $process->setTimeout(null);
        $process->run();

        if (!$process->isSuccessful()) {
            throw new \RuntimeException($process->getErrorOutput());
        }
    }
1055800
public function runAsProcessReturningProcessObject(string $command) : Process
    {
        $process = new Process($command);
        $process->run();
        $process->setTimeout(null);
        $process->setIdleTimeout(60);
        $process->wait();

        return $process;
    }
1205009
protected function runProcess($callback = null)
    {
        $process = $this->processBuilder
            ->setArguments(
                $this->prepareArguments()
            )
            ->getProcess();

        // exit code
        $result = $process->run($callback);

        // text-mode
        if (null === $callback) {
            $result = $process->getOutput();

            if (false === $process->isSuccessful()) {
                $process->getErrorOutput();
            }
        }

        return $result;
    }
290330
public function process($options)
    {
        $tool = sprintf('php %s %s %s', $this->toolPathFinder->find('phpunit-randomizer'), '--order rand', $options);

        $process = new Process($tool);

        return $this->runProcess($process);
    }
1341498
public function run(callable $callback, array $argsCollection)
    {
        $this->collector->init();
        $children = [];
        foreach ($argsCollection as $key => $args) {
            $pid = pcntl_fork();
            switch ($pid) {
                case -1:
                    throw new \RuntimeException(sprintf('Unable to fork process %d of %d', $key,
                        count($argsCollection)));
                case 0: // child
                    $this->collector->setValue($key, call_user_func_array($callback, $args));
                    exit(0);
                default: //parent
                    $children[] = $pid;
            }
        }
        foreach ($children as $child) {
            do {
                pcntl_waitpid($child, $status);
            } while (!pcntl_wifexited($status));
        }
        return $this->collector->getValues(array_keys($argsCollection));
    }
166224
public function run()
    {
        $process = $this->getProcess();

        $process->setTimeout($this->timeout);

        if ($this->console instanceof Command) {
            $process->run(function ($type, $line) {
                $this->console->line($line);
            });
        }

        return $process;
    }
425668
public function executeCommand($command)
    {
        $cmd = sprintf('%s %s', $this->binaryPath, $command);
        $p = new Process($cmd);
        $p->run();
        if ($p->isSuccessful()) {
            return $p->getOutput();
        } else {
            throw new \RuntimeException(sprintf('pygmentize failed with the error: %s', $p->getErrorOutput()));
        }
    }