Working with Sub-processes in Ruby

From PeformIQ Upgrade
Jump to navigation Jump to search

When working on a POSIX OS you can use fork and exec.

fork => Create a subprocess
exec => Replace current process with another process

You can advise your main-process that you do not need to wait in the completion of the sub-process using the Process.detach call.

job1 = fork do
  exec "/path/to/daemon01"
end

Process.detach(job1)

...