如何让过程PID由Symfony启动?

时间:2022-05-30 16:44:39

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

如何让过程PID由Symfony启动?波纹管的代码

$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.

返回PID 1488。但是在具有相同PID的系统中没有进程(没有vlc,没有php)。

Edit

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

显示的代码运行在app/控制台(Symfony\组件\控制台命令)

2 个解决方案

#1


2  

Process forking

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

进程不太可能独立地派生它们的UI并让启动进程正常地结束,例如。

----> 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.

还要注意,当父进程退出(您的脚本)时,子进程也可以通过监听SIGHUP信号选择退出。如果你还没有这样做,你可以在你调查的时候添加一个sleep()语句,让你的脚本“活”得更长。

#2


0  

Another approach that may work in some situations is doing it inversely like a script to grep parse a 'ps -A' containing the desired process (PHP e.g.) and rip off PID from the result. You don't have control on "who's who" on the result set but have control on "who's" actually running.

另一种可能在某些情况下起作用的方法是使用与grep解析包含所需进程(PHP)的'ps -A'和从结果中提取PID相反的脚本。你不能控制结果集中的“谁是谁”,但可以控制“谁是谁”实际上正在运行。

#1


2  

Process forking

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

进程不太可能独立地派生它们的UI并让启动进程正常地结束,例如。

----> 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.

还要注意,当父进程退出(您的脚本)时,子进程也可以通过监听SIGHUP信号选择退出。如果你还没有这样做,你可以在你调查的时候添加一个sleep()语句,让你的脚本“活”得更长。

#2


0  

Another approach that may work in some situations is doing it inversely like a script to grep parse a 'ps -A' containing the desired process (PHP e.g.) and rip off PID from the result. You don't have control on "who's who" on the result set but have control on "who's" actually running.

另一种可能在某些情况下起作用的方法是使用与grep解析包含所需进程(PHP)的'ps -A'和从结果中提取PID相反的脚本。你不能控制结果集中的“谁是谁”,但可以控制“谁是谁”实际上正在运行。