All -- I am stuck on a perl script that does a forking queue. (I am trying to kick off 10 AIX system backups at the same time). My script will also monitor if one of the backups runs too long and kill that process. This is when my problem occurs, if I killed off the forked process (see below my hash #child_output), I don't get any output, because the ssh has not finished. If the process does complete normally, I get the output that I expected. I am not sure if there is a way around my problem, given how I wrote my code, but I thought I might see if someone else has any insight...
sub fork_backup
{
my $lpar = shift;
if ( ( scalar keys %children ) < $max_children )
{
my $pid = fork;
if ( $pid )
{
# this is parent process
$children{$pid} = $lpar;
print "Child Backup [$pid][".$children{$pid}."] started a
+t ".localtime()."\n";
$processing_time{$pid} = time();
}
else
{
if ( not defined $pid )
{
die "\n\nWoah: Failed to fork a child!\n";
}
# this is child process
# This is where the meat goes!
my $backup_command;
if ( ($lpar_oslevel{$lpar}) eq "5.3")
{ $backup_command = "ls -al /;sleep 20"; } #Put the rea
+l sysback command in here later (for 5.3)
else
{ $backup_command = "ls -al /;sleep 30"; } #Put the rea
+l sysback command in here later (for all other)
# Fire off the backup command, whew!
$child_output{$lpar}=`ssh -q $lpar "$backup_command"`;
# exit child process
exit 0;
}
}
else
{
# too much child labor! queue for later under complete_backu
+p
unshift(@queue,$lpar);
}
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.