def sfork(command, &block)
pipe_me_in, pipe_peer_out = IO.pipe
pipe_peer_in, pipe_me_out = IO.pipe
Thread.critical = true
STDOUT.flush
ProcessController.each_active_object do |pc|
for jobs in pc.active_jobs
jobs.flush
end
end
pid = fork {
Thread.critical = true
Thread.list.each do |th|
th.kill unless [Thread.main, Thread.current].include?(th)
end
STDIN.reopen(pipe_peer_in)
STDOUT.reopen(pipe_peer_out)
ObjectSpace.each_object(IO) do |io|
if ![STDIN, STDOUT, STDERR].include?(io)
io.close unless io.closed?
end
end
yield
}
pipe_peer_in.close
pipe_peer_out.close
command.notify "job(%name:##{pid}) start", @shell.debug?
Thread.critical = false
th = Thread.start {
Thread.critical = true
begin
_pid = nil
command.notify("job(%id) start to waiting finish.", @shell.debug?)
Thread.critical = false
_pid = Process.waitpid(pid, nil)
rescue Errno::ECHILD
command.notify "warn: job(%id) was done already waitipd."
_pid = true
ensure
if _pid
else
command.notify("notice: Process finishing...",
"wait for Job[%id] to finish.",
"You can use Shell#transact or Shell#check_point for more safe execution.")
redo
end
Thread.exclusive do
@job_monitor.synchronize do
terminate_job(command)
@job_condition.signal
command.notify "job(%id) finish.", @shell.debug?
end
end
end
}
return pid, pipe_me_in, pipe_me_out
end