开发者

Best way of spawning and monitoring processes?

开发者 https://www.devze.com 2023-03-13 07:35 出处:网络
I\'m going to be building an app that spawns three system processes (Linux). They will run for an estimates 2-8 minutes, and th开发者_开发百科en finish their work and exit. Pretty standard.

I'm going to be building an app that spawns three system processes (Linux). They will run for an estimates 2-8 minutes, and th开发者_开发百科en finish their work and exit. Pretty standard.

I'm wondering the best way of:

  • Spawning the processes
  • Logging their output
  • Performing an action when the process has finished its work

Any help greatly appreciated. Thanks!


If you have the extension, use the PCNTL functions. They abstract you from getting the process ids, checking their status and so.

  • pcntl_exec to start the process
  • pcntl_waitpid with WNOHANG option to poll their current status
  • To log the output, append > /tmp/somefile 2>&1 to their command. use a different temporary filename for each process - you could generate it with tempnam()
0

精彩评论

暂无评论...
验证码 换一张
取 消