-
-
Save bkeepers/d62f5f2c664134700ad3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
children = {} | |
trap :CLD do | |
pid = Process.wait | |
i = children.delete(pid) | |
puts "Reaping #{i}: #{pid}" | |
children[fork { sleep rand(5) }] = i | |
end | |
3.times do |i| | |
pid = fork { sleep rand(5) } | |
puts "Spawned #{i}: #{pid}" | |
children[pid] = i | |
end | |
loop do | |
sleep | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A bomb-proof implementation: aggressively avoids zombies and hash misses.