Search code examples
phplinuxsymfonypidsymfony-process

How to get process PID started by Symfony?


How can I get PID of process started by Symfony? The code bellow

$process = new \Symfony\Component\Process\Process('vlc');
$process->start();
return $process->getPid();

returns PID 1488. But there is no process (no vlc, no php) in system with same PID.

Edit

Presented code runs in app/console (Symfony\Component\Console\Command\Command)


Solution

  • Process forking

    It's not unlikely for processes to spawn off their UI separately and letting the starter process end normally, i.e.

    ----> vlc (1488) ---> EOL
           |
           +--> vlc-ui (??) ---> Application
    

    This behaviour is observable by running the application from the command line and checking whether the prompt returns almost immediately.

    Hangup signal

    Also note that when a parent process exits (your script), the child process may choose to also exit by listening to SIGHUP signals. If you're not doing so already, you could let your script "live" longer by adding a sleep() statement while you investigate.