Project

General

Profile

Bug #3100 » forktest.rb

alk (Aliaksey Kandratsenka), 04/05/2010 08:14 PM

 
require 'pty'

$arg = ARGV[0] ? ARGV[0].to_i : 10000

if $arg < 10
puts "Hang should be very probable. Try again if it doesn't hang"
else
puts "$arg is #{$arg} which is too large. Pass anything from 1 to 10 to trigger ruby hang"
end

loop do
pid = nil

info = []

4.times do
r = w = p = nil
PTY.spawn("ruby -e '(4000000/#{$arg}).times {}; sleep 0.2; puts 1'") do |rd,wr,pd|
r,w,p = rd,wr,pd
end
info << [r,w,p]
end

info.each do |r,w,*e|
r.gets
w.close
r.close
end

print "."
STDOUT.flush
end
(1-1/3)