fork BUG?
Andrew Belashov
bel at orel.ru
Fri Jul 25 03:52:44 PDT 2003
Hello!
Help me to analyse a problem.
Perl crashing in child after fork().
My script working perfectly on FreeBSD 4.7R i386.
---Test session------------------------------------------------
bel at white$ uname -a
FreeBSD white 5.1-RELEASE FreeBSD 5.1-RELEASE #0: Thu Jul 24 11:18:15
MSD 2003 bel at white:/usr/obj/usr/src/sys/WHITE sparc64
bel at white$ pkg_version -v|grep ^perl
perl-5.6.1_11 < needs updating (port has 5.6.1_13)
bel at white$ perl forkbug.pl
...
Main: sum = 39951.2526718337, cnt = 80000
Parent working...
perl in realloc(): warning: modified (chunk-) pointer
Out of memory!
perl in free(): warning: modified (chunk-) pointer
Parent: sum = 39951.2526718337, cnt = 80000
Parent waiting a child...
Parent exiting...
---End session-------------------------------------------------
With best regards,
Andrew Belashov.
-------------- next part --------------
#!/usr/bin/perl -w
use IO::Handle;
my %arr;
my @tmpl = ('.', '/', '0'..'9', 'a'..'z', 'A'..'Z');
my $lentmpl = @tmpl;
sub docheck {
my $prefix = shift;
my $sum = 0; my $cnt = 0;
foreach my $key (keys(%arr)) {
$sum += $arr{$key}; $cnt++;
}
print "$prefix: sum = $sum, cnt = $cnt\n";
}
STDOUT->autoflush(1);
for (my $i = 0; $i < 80000; $i++) {
my $key = '';
foreach my $j (0..8) {
$key .= $tmpl[rand($lentmpl)];
}
$arr{$key} = rand;
print "." if (($i % 1000) == 0);
}
print "\n";
&docheck('Main');
die "fork()" unless defined(my $pid = fork());
if ($pid) {
print "Parent working...\n";
&docheck('Parent');
print "Parent waiting a child...\n";
wait();
print "Parent exiting...\n";
exit(0);
} else {
print "Child working...\n";
&docheck('Child');
print "Child exiting...\n";
exit(0);
}
More information about the freebsd-sparc64
mailing list