I am trying to fork off a series of child processes (~10) having each child
connect to an Oracle 8i database . The child should process the data and
return a value (using pipes). This works great for one child, but when I
create a series of children I get the following Windows Error Message:
perl.exe - Application Error
The instruction at "0x01e24f28" reference memory at "0x0000000c". The memory
could not be "read".
I am working on a Win200 box with ActiveState perl (5.6.1 build 631)....not
my choice, but what's a dev to do? I tested the code with both DBD::Oracle
and Win::ODBC - always the same memory error.
Any suggestions/advice would be greatly appreciated. Is this even possible
on a Window box?
Mike Boyle
==========
#!/usr/bin/perl
#
# Example/testing of fork to
# as a means to speed-up
# PayHurt/PayLoss Reports.
#
use DBI;
use Carp;
use strict;
use Errno qw(EAGAIN);
use Win32::ODBC;
$\ = "\n";
$, = " :: ";
my $db;
my $SqlStatement;
my %Data;
my $DSN = "DSN=TESTBLAH;UID=blah;PWD=blah;";
pipe CREAD, PWRITE;
pipe PREAD, CWRITE;
$SIG{CHLD} = 'IGNORE';
my $child;
my @id = qw(2 5 8 77 101 102 103 104 105 212);
my @kids;
my $kids;
my @pipes;
for (0..9)
{
if ($child = fork)
{ #i'm the child
die "cannot fork: $! " unless defined $child;
close PREAD;
close PWRITE;
syswrite CWRITE, GetDBName($id[$_]);
exit;
}
else
{
close CREAD; close CWRITE;
$kids .= <PREAD>;
pipe CREAD, PWRITE;
pipe PREAD, CWRITE;
}
}
print $kids;
sub xGetDBName
{
my ($seq) = @_;
my $dbh = DBI->connect('DBI:Oracle:TESTPROD', 'DEV_ADMIN', 'DEV_ADMIN');
my $sql = " select rglogonname from auth.person where person_seq = $seq
";
my $sth = $dbh->prepare($sql);
$sth-> execute();
my $t;
while (my @row = $sth->fetchrow_array)
{
$t = ( "My name is : ".$row[0]."\n");
}
$sth->finish();
$dbh->disconnect();
return ("$t");
}
sub GetDBName
{
my ($seq) = @_;
if (!($db = new Win32::ODBC($DSN)))
{
print "Error connecting to $DSN\n";
print "Error: " . Win32::ODBC::Error() . "\n";
exit;
}
$SqlStatement = " select rglogonname from auth.person where person_seq =
$seq ";
if ($db->Sql($SqlStatement))
{
$db->Close();
exit;
}
while($db->FetchRow())
{
undef %Data;
%Data = $db->DataHash();
my $key;
foreach $key (keys %Data)
{
my $val = ($Data{$key}) ? $Data{$key} : "";
$t .= "$key = $val|";
}
}
$db->Close();
return ("$t\n");
}