Best way to spawn and monitor processes?

I am going to create an application that spawns three system processes (Linux). They will run for 2-8 minutes, and then finish work and exit. Pretty standard.

I am wondering what is the best way:

  • Spawning processes
  • Record their output
  • Execution of an action when a process has completed its work.

Any help is greatly appreciated. Thank!

+3
source share
1 answer

If you have an extension, use the PCNTL functions. They abstract you from obtaining process identifiers, checking their status, etc.

  • pcntl_execto start the process
  • pcntl_waitpidwith an option WNOHANGto poll your current state.
  • , > /tmp/somefile 2>&1 . - tempnam()
+1

All Articles