Project

General

Profile

Bug #4579 ยป test_fork_random.rb

normalperson (Eric Wong), 04/15/2011 11:46 AM

 
1
require "openssl"
2
require "securerandom"
3

    
4
SecureRandom.random_bytes(4)
5
pid = fork do
6
  p [ $$, SecureRandom.random_bytes(4) ]
7
end
8
Process.waitpid2(pid)
9

    
10
loop do
11
  xpid = fork do
12
    p [ $$, SecureRandom.random_bytes(4) ] if $$ == pid
13
  end
14
  Process.waitpid2(xpid)
15
  break if xpid == pid
16
end