Hi I have a perl script that does the following, creates 10 child processes and process them seperately.

use Oraperl; use DBI; use strict; use DBD::Oracle qw(:ora_types); use Time::Local; use POSIX; my @SharedPlanAccts=(); my $lda = ""; my $two_task = ""; my $pid=$$; my $todays_date = `date +\%Y\%m\%d`; my $curr_time = `date +\%H\%M\%S`; my $noOfInputDomainsRunning = 0; my $APIDomainIndex = 0; my ($i1, $k1, $j1) = 0; my @pids; my $totalAccts = 0; my $acctsPerChild = 0; my $n = 10; openLogFile(); LoginDB(); fetchAccounts(); for( $i1=1; $i1 <= $n; $i1++ ) { $pids[$k1] = fork(); if ( $pids[$k1] == 0 ) { $lda->{InactiveDestroy} = 1; ProcessRecords( @SharedPlanAccts, $i1, $n, $totalAccts ); exit(0); } else { $k1++; } } foreach (@pids) { #parent process waits here until all child process goes down waitpid($_,0); } LogoffDB(); sub openLogFile { my $p2klogs = $ENV{"LOGS"}; my $log_file = $p2klogs . "/" . $prog_name ."_" . $todays_date +. $curr_time ."_".$$.".log"; unless ( open (LOGF,">>$log_file") ) { print ("Open append failed for log file = $log_file\n +"); print ("$prog_name process terminated abnormally.\n"); exit 1; } } sub LoginDB() { my ( $db_user, $db_pswd ); $two_task = $ENV{"TWO_TASK"}; $db_user = $ENV{"DB_USER_NAME"}; $db_pswd = $ENV{"DB_PASSWORD"}; #-- connect to database if ( $db_user eq "/" ){ $lda = DBI->connect("DBI:Oracle:" . $two_task ) || logDBIError ("logon to Oracle failed"); } else{ $lda = DBI->connect("DBI:Oracle:" . $two_task, $db_user, $db +_pswd); } } sub LogoffDB() { $lda->disconnect || logDBIError("Failed to disconnect database han +dle"); logMessage ("The $prog_name process successfully completed "); close(LOGF); } sub fetchAccounts() { my $res = $lda->prepare(" select distinct acct_nbr acct_asgm +"); if(defined($res)) { $res->execute(); while (my @row = $res->fetchrow_array() ) { push(@SharedPlanAccts,@row); } } else { logMessage("Could not execute the query!"); } $totalAccts = @SharedPlanAccts; logMessage ( "Total Number of accts under validation : $totalA +ccts "); $acctsPerChild = floor ($totalAccts/$n ); logMessage ("Each child process around $acctsPerChild accounts "); } sub ProcessRecords() { my ( @acctArray,$myNbr,$totalChilds,$totalAccts) = @_; my $begIndex = 0; my $endIndex = 0; my $acctsProcessed = 0; openLogFile(); LoginDB(); $begIndex = ($acctsPerChild * $myNbr ) - $acctsPerChild; $endIndex = ($acctsPerChild * $myNbr ) - 1; if ( $myNbr == $n ) { $endIndex = $totalAccts - 1; } my @acctList = @acctArray[$begIndex .. $endIndex]; foreach my $a (@acctList) { logMessage ("Acct Under Validation : $a "); if( defined ($a) ) { my $found = 0; my ( $AcctNbr, $CycCd, $CycEndDt ); my $dly1 = $lda ->prepare("select acct_nbr,cycle_cd,cy +cle_end_dt from Daily1 where acct_nbr= ? and rownum <2 order by cycl +e_end_dt "); my $dly2 = $lda ->prepare("select acct_nbr,cycle_cd,cy +cle_end_dt from Daily2 where acct_nbr= ? and rownum < 2 order by c +ycle_end_dt "); $dly1->bind_param(1,$a); $dly2->bind_param(1,$a); $dly1->execute(); $dly1->bind_col(1,\$AcctNbr); $dly1->bind_col(2,\$CycCd); $dly1->bind_col(3,\$CycEndDt); $acctsProcessed=$acctsProcessed + 1; while ( $dly1->fetch) { $found++; rerateandupdate($AcctNbr,$CycCd,$CycEndDt); last; } if ($found == 0) { $dly2->execute(); $dly2->bind_col(1,\$AcctNbr); $dly2->bind_col(2,\$CycCd); $dly2->bind_col(3,\$CycEndDt); while ( $dly2->fetch ) { rerateandupdate($AcctNbr,$CycCd,$CycEndDt); last; } } } } logMessage ("Total Number of Accts processed : $acctsProcessed + "); LogoffDB(); } sub rerateandupdate { logMessage ("Acct rerated "); } sub logMessage { my($message) = shift; my $log_date = `date +%m/%d/%Y`; my $log_time = `date +%T`; chop($log_date, $log_time); print LOGF ("$log_date:$log_time | $message\n"); }

What the script does is..first it fetches accts from a table (in sub fetchAccounts ) ,forks 10 child process and pass the accts for further processing. These child process will also need to connect to DB. But during execution,I'm getting DB errors like : DBD::Oracle::db DESTROY failed: ORA-03135: connection lost contact (DBD ERROR: OCISessionEnd) Can anyone please tell tell me whats wrong here :(


In reply to Problem with forking in perl by rkrish

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.