def fork
last_arg = ARGV.last
if last_arg =~ /child#\d+/
@i += 1
num = last_arg.split('#').last.to_i
if num == @i
if block_given?
status = 0
begin
yield
rescue Exception
status = -1
ensure
return status
end
end
return nil
else
return false
end
end
cmd = 'ruby -I "' + $LOAD_PATH.join(File::PATH_SEPARATOR) << '" "'
cmd << File.expand_path($PROGRAM_NAME) << '" ' << ARGV.join(' ')
cmd << ' child#' << @child_pids.length.to_s
startinfo = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
startinfo = startinfo.pack('LLLLLLLLLLLLSSLLLL')
procinfo = [0,0,0,0].pack('LLLL')
rv = CreateProcess(0, cmd, 0, 0, 1, 0, 0, 0, startinfo, procinfo)
if rv == 0
raise ProcessError, get_last_error
end
pid = procinfo[8,4].unpack('L').first
@child_pids.push(pid)
pid
end