Best way of spawning and monitoring processes?
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_execto start the processpcntl_waitpidwithWNOHANGoption to poll their current status- To log the output, append
> /tmp/somefile 2>&1to their command. use a different temporary filename for each process - you could generate it withtempnam()
加载中,请稍侯......
精彩评论