I have an issue with rand() while fork()ing and using IO::Socket::SSL.
In all forked processes rand() gives me the same set of random numbers. If I call rand() several times I get random numbers as expected, but in all forked processes I get the same random set.
If I remove IO::Socket::SSL the set is random in all processes.
I've reduced the case down to this:
use strict; use IO::Socket::SSL; foreach (1 .. 5) { my $pid = fork(); next if $pid; random(); random(); exit; } sub random { print sprintf("Process %d: %d", $$, int(rand(100000))), "\n"; }
If I run the script I get this output:
$ perl fork_rand.pl Process 13788: 32768 Process 13788: 3778 Process 13789: 32768 Process 13789: 3778 Process 13790: 32768 Process 13790: 3778 Process 13791: 32768 Process 13791: 3778 Process 13792: 32768 Process 13792: 3778
I would expect the numbers to be random in all processes -- not return the same set of numbers.
If I remove IO::Socket::SSL everything works as expected:
$ perl fork_rand.pl Process 13806: 94050 Process 13806: 14790 Process 13807: 89099 Process 13807: 93200 Process 13808: 48447 Process 13808: 14001 Process 13809: 28378 Process 13809: 71603 Process 13810: 44245 Process 13810: 86800
Is this a known bug?
I've tested on both Linux and FreeBSD, with latest version of IO::Socket::SSL and Perl 5.8.8.
In reply to fork(), IO::Socket::SSL and rand() by digmon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |