Method: EventCore::MainLoop#spawn

Defined in:
lib/event_core.rb

#spawn(*args, &block) ⇒ Object

Like Process.spawn(), invoking the given block in the main loop when the process child process exits. The block is called with the Process::Status object of the child.

WARNING: The main loop install a SIGCHLD handler to automatically wait() on processes started this way. So this function will not work correctly if you tamper with SIGCHLD yourself.

When you quit the loop any non-waited for children will be detached with Process.detach() to prevent zombies.

Returns the PID of the child (that you should /not/ wait() on).



572
573
574
575
576
577
578
579
580
581
582
# File 'lib/event_core.rb', line 572

def spawn(*args, &block)
  if @sigchld_source.nil?
    @sigchld_source = add_unix_signal("CHLD") {
      reap_children
    }
  end

  pid = Process.spawn(*args)
  @children << {:pid => pid, :block => block}
  pid
end