### BEGINING OF FORK
#
my $kidpid;
my $parentpid = $$;
if (!defined($kidpid = fork())) {
# fork returned undef, so failed
print "cannot fork: $!";
}
elsif ($kidpid == 0) {
sleep(3600);
my ($date, $Stime, $Ctime, $J, $Temp1, $Temp2, $bpdbjobs);
my (@JOBID, @PIDS, @times, @bpdbLines);
while(1) {
### parsing the input
$bpdbjobs = `$BPDBJOBS | grep Active | grep -v PID`;
@bpdbLines = split /\n/, $bpdbjobs;
for($J = 0; $J < @bpdbLines; $J++) {
$bpdbLines[$J] = $bpdbLines[$J] . "\n";
$bpdbLines[$J] =~ /^(\d+)\s/;
$JOBID[$J] = $1;
$bpdbLines[$J] =~ /\s(\d+)$/;
$PIDS[$J] = $1;
if( $PID[$J] == $parentpid) {
$PIDS[$J]=undef;
$JOBID[$J]=undef;
$J--;
}
}
for( $J = 0; $J < @PIDS ; $J++) { #get the time the job started
chomp ($times[$J] = `/bp/bin/bpps | grep $PIDS[$J] | /usr/local/bin/perl -lane 'print \$F[4]'`);
$times[$j]=parsedate($times[$j]);
}
### time checks
$Ctime = time;
for($J = 0; $J < @PIDS; $J++) {
$Temp1 = $Ctime - $times[$j];
if($Temp1 > 7200) {
$Temp2 = "/usr/openv/netbackup/bin/admincmd/bpdbjobs -cancel $JOBID[$J]"; #cancel if job runs longer than
2 hours
print "$Temp2\n";
system($Temp2);
unless (open (todayHungClientsLogP, ">>$HungClientsLog")) {
print (" HungClients: unable to open output <$HungClientsLog>\n");
}
else {
# print (todayHungClientsLogP " Running Time = $Temp1 >>");
print (todayHungClientsLogP "$Temp2\n");
close (todayHungClientsLogP);
}
}
}
sleep(1800);
$alive = `/bin/ps -ef | grep $parentpid | grep -v grep`;
unless($alive ne "") {
exit;
}
}
}
else {
#do the rest of the script here.
####
#!/usr/local/bin/perl -w
use strict;
my $parentpid = $$;
my $kidpid;
print "This is the original process the pid = $$\n";
if (!defined ($kidpid = fork())) {
#fork failed.
print "Can't fork: $!";
}
elsif ($kidpid ==0) {
print "\tThis is the child process.. parentpid = $parentpid\n";
print "\tThis is the child process its pid = $$\n";
}
else {
sleep(1);
print "This is the return to the parent process\n";
}
####
This is the original process the pid = 5292
This is the child process.. parentpid = 5292
This is the child process its pid = 5293
This is the return to the parent process