Last active
August 29, 2015 13:58
-
-
Save p5k6/10055749 to your computer and use it in GitHub Desktop.
Using Ruby to spawn multiple processes, communicate with them and wait/join the threads
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
arr = [] | |
10.times do |i| | |
cmd = "ping -c #{(rand(0)*10).to_i + 1} 127.0.0.1" | |
pid = spawn(cmd, {out: "/dev/null"}) | |
puts "#{pid}\n" | |
arr[i] = Process.detach(pid) | |
end | |
arr.each { |t| t.join; print "#{t.status}: #{t.pid}" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment