Conflicting children...

Q

Qi

I try to use 3 children to load data into Oracle dataabase.
But my script is hanging. I suspect the hanging is caused by writing
the same logfile by the children.
I can not reproduce it. The hanging happens only occasionally.
Any help is appreciated. Thanks.

while (!finished) {
if ($Processed == 3) {
if (($cpid = wait()) != -1) {
print FH_LOG ("Child ready...\n");
}
} else {
print FH_LOG ("----- Uploading new file\n");
StartChild;
}
}

sub StartChild {
$cpid = fork();
die unless defined $cpid;

if (! $cpid) {
system ("sqlldr parfile=File.PAR");
exit;
} else {
print ("New child: $cpid\n");
}
}
 
A

A. Sinan Unur

I try to use 3 children to load data into Oracle dataabase.

Why?

Looking at your code, I see that you are not using strict and warnings.
Please read the posting guidelines for this group, and follow the
recommendations for coming up with a short script that still exhibits
the problem. In doing so, you will probably come up with the answer
yourself.
I suspect the hanging is caused by writing
the same logfile by the children.

I am not sure why you would think that:

#!/usr/bin/perl

use strict;
use warnings;

use Time::HiRes qw(usleep);

my $logfile = q{logfile.txt};

open my $log, '>', $logfile
or die "Cannot open $logfile: $!";

$SIG{CHLD} = \&REAPER;

select $log;
$| = 1;

for my $child (1 .. 3) {
my $cid = fork;
if (defined $cid) {
if ($cid == 0) {
for my $line (1 .. 1_000_000) {
print { $log } "Child: $child\tLine $line\n"
or die "Child $child ($$): cannot write to $logfile: $!
\n";
usleep(int rand(100));
}
exit;
} else {
warn "Spawned child $child($cid)\n";
}
}
}

close $log or die "Cannot close $logfile: $!";


sub REAPER {
my $waitedpid = wait;
$SIG{CHLD} = \&REAPER;
}
 
X

xhoster

Qi said:
I try to use 3 children to load data into Oracle dataabase.

Why not Parallel::ForkManager?
But my script is hanging. I suspect

Don't suspect. Sprinkle warn statements throughout your code to monitor
progress. Where does the progress stop?

Have you ruled out the possibility that your script just reaches a batch
of files which take a really long time to load into Oracle?

the hanging is caused by writing
the same logfile by the children.

In the code you posted, only the parent writes to the logfile. The
children do not.
I can not reproduce it. The hanging happens only occasionally.
Any help is appreciated. Thanks.

while (!finished) {
if ($Processed == 3) {

Since $Processed is never referenced elsewhere, I have to assume it will
never equal 3, and thus this code branch will never execute. Also, you
do not seem to be using strict. Shame on you.

Xho
 
Q

Qi

Guys, thanks for reply.

Xho, I'm only a beginner. Forgive me. I the future I'll use strict.

I think that my problem is caused by fork not returning unique $cpid
($cpid = fork();).
 
X

xhoster

Qi said:
Guys, thanks for reply.

Xho, I'm only a beginner. Forgive me. I the future I'll use strict.

Thank you for using strict in the future, and you are forgiven. But please
also quote some context when you reply.
I think that my problem is caused by fork not returning unique $cpid
($cpid = fork();).

From the code you posted, that would not be a problem because the return
value of fork() is not used in a meaningful way, other than to detect if
you are in the parent or the child, so it does't matter if it is unique or
not. (And while the false values returned by fork are obviously not unique,
it is hard to believe that the true values are not unique in your case.
They should start recycling only after tens of thousands of forks *and*
after the child that had that pid last time has exited.)

Xho
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,591
Members
45,100
Latest member
MelodeeFaj
Top