Skip to content

Instantly share code, notes, and snippets.

@p5k6
Last active August 29, 2015 13:58
Show Gist options
  • Save p5k6/10055749 to your computer and use it in GitHub Desktop.
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
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