Oh, it was definitely working. It was tested loading into a truncated
table, with the .dat file deleted beforehand. Plus the script deleted
the .dat file and replaces it. That data has to be coming from
somewhere B^)
Okay, for the code...
In the control script that runs the other processes:
my %pids;
open PID, '/opt/access/scripts/newt3util.pid'
or die "Can't read PID file newt3util.pid: $!";
map {chomp; $pids{$_} = 1} (<PID>);
close PID;
while (grep $_, values %pids) {
# while there are non zero values in the pids hash
my %procs = map {$_ => 1} split /\n/, `ps -eo pid`;
# store the current list of running system processes in the procs
hash
for my $pid (keys %pids) {
# for every pid in the pids hash
unless ($procs{$pid}) {
# set the value to zero if it's not in the procs hash
# because that means it's done
$pids{$pid} = 0;
}
}
sleep 1;
# rest for a second before checking again
}
These pids are coming from the PID file which is written to by the
parent that kicks everything off:
$util->logIt("Slicing to $num_per_child circuits per child process:
covers " .
$num_per_child * $maxchildren . "\n");
warn "Got ", scalar(@{$all_circuits}), " circuits.\n";
while ($all_circuits) {
if (scalar @{$all_circuits} > $num_per_child) {
push @{$circuits}, [splice @{$all_circuits}, 0,
$num_per_child];
}
else {
push @{$circuits}, $all_circuits;
last;
}
}
undef $all_circuits;
open PID, ">/opt/access/scripts/newt3util.pid";
print PID "$$\n";
my $connid = 9;
for my $batch (@{$circuits}) {
my $pid;
$connid++;
if ($connid > 2

{
$util->logIt("Out of valid connection IDs. Existing processes
will ".
"continue but no more circuits can be processed.
Run in ".
"non-init mode (no -i) when this is finished to
get the rest.\n");
last;
}
if ($pid = fork) {
print PID "$pid\n";
next;
}
else {
$util->logIt("Starting child process on id $connid with " .
scalar(@{$batch}) . " circuits.\n");
$util->{userid} = sprintf '*******%03d', $connid;
$util->setupConn; #
$util->get_circuit_xx($batch, \&store_line);
$util->logIt("Finished child process $connid.\n");
last;
}
}
Note there are some slight changes I had to make, i.e. some of the
subroutines and warnings contained the name of the screen based system
to connect to, and to post this on the net I did have to censor that,
replacing the name with 'conn' where applicable, and a few tiny other
similar things. Work rules, had to. Same with the starred out userid.