APM: RE: Killing spawned processes
Bakken, Tom - Temple, TX
tom.bakken at tx.usda.gov
Mon Jul 26 14:09:37 CDT 2004
Bill,
The parent id was 160, the child was -3168
Tom Bakken
Information Resource Manager
Texas USDA, Rural Development
-----Original Message-----
From: Bill Raty [mailto:bill.raty at gmail.com]
Sent: Monday, July 26, 2004 12:19 PM
To: Bakken, Tom - Temple, TX
Subject: Re: Killing spawned processes
Tom,
Sorry for the delay in answering, been pushing a product deadline all
weekend.
We need to make sure the ChildPid is different than the parent process
id. Could you add this statement to the start of your script?:
print "parent pid: $$\n";
Then right before your 'kill' add
print "child pid: $ChildPid\n";
Please rerun and let me know what these results are. I need to know
if it is perl or Windows that is misbehaving.
-Bill
On Mon, 26 Jul 2004 09:25:09 -0600, Bakken, Tom - Temple, TX
<tom.bakken at tx.usda.gov> wrote:
> I tried Bill's spawn subroutine on a system that supports fork. And
it
> does allow the uptime command to run for at most 20 seconds as
> advertised. If uptime succeeds it then reads the results of uptime
and
> processes it as intended. However, if uptime does run for 20 seconds,
> the kill program terminates my perl script rather than the child
> process.
>
> Bill, I may have misinterpreted your instructions, but I think I'm
> stumbling close to what I want
>
> What am I doing wrong?
>
> SNIP----
> sub spawn (&) {
> my ($CodeRef) = @_;
> my $pid;
> unless ($pid = fork) {
> $CodeRef->(); # Start the child process. Make sure
it
> exits too!
> exit;
> }
> $SIG{CHLD} = "IGNORE"; # Make sure we don't have any ghost
> processes. Have perl do the waitpid
> return $pid;
> }
> sub GetWorkstationUptime { # Copy files to server using a list of
> machine names
> my $ListOfWorkstationsArrayRef = shift;
> my $Count = 0;
> foreach (sort @{$ListOfWorkstationsArrayRef}) {
> my ($MachineName, $Description, $DnsHostName,
> $OS, $WhenChanged, $WhenCreated) = split /\|/, $_;
> #### next unless uc($MachineName) =~ /TXTEMPLE/;
> next unless uc($MachineName) =~ /TXBELLVILLD/;
> $Count++;
> unless ($MachineName =~ /$StateAbbrev/i) {
> print "$Count ALERT!!! No MachineName for this Active Directory
> record.\n";
> print LOGFILE "$Count ALERT!!! No MachineName for this
Active
> Directory record.\n";
> print DATAFILE
> "$Count\t--------------\t-------------------\t---\t---\t---\tNo
Machine
> Name\n";
> next;
> }
> print "$Count: Checking last reboot on: $MachineName\n";
> my $ChildPid = spawn {
> print LOGFILE "$Count: Checking last reboot on: $MachineName\n";
> $Status = system "uptime \\\\$MachineName > /nul";
> unless ($Status == 0) {
> $Error++;
> if($OS =~ /Windows XP Professional/) {
> print "ALERT!!! Could not connect to $MachineName.
> $Description Error: $?\n";
> print LOGFILE " ALERT!!! Could not connect to
> $MachineName. $Description Error: $?\n";
> }
> else {
> print "ALERT!!! Could not connect to $MachineName.
> $Description Error: $?\n";
> print LOGFILE " ALERT!!! Could not connect to
> $MachineName. $Description Error: $?\n";
> print "ALERT!!! OS Not Windows XP Professional. Detected:
> $OS\n";
> print LOGFILE " ALERT!!! OS Not Windows XP Professional.
> Detected: $OS\n";
> }
> print DATAFILE
> "$Count\t$MachineName\t-------------------\t---\t---\t---\tCould not
> connect\n";
> next;
> }
> }; # Don't forget the semicolon here!!!!
> sleep 20; # Give uptime 20 seconds to run
> kill TERM => $ChildPid; # Kill after that amount of time
> my $Results = `uptime \\\\$MachineName`;
> my ($Days, $Hours, $Minutes, $Seconds) = split /,/, $Results;
> Blah blah
> ..
> ..
> ..
> ..
> } # End GetWorkstationUptime subroutine
>
>
> Tom Bakken
>
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Tom.Bakken at tx.usda.gov.vcf
Type: text/x-vcard
Size: 460 bytes
Desc: Tom.Bakken at tx.usda.gov.vcf
Url : http://mail.pm.org/pipermail/austin/attachments/20040726/ba92ea7c/Tom.Bakkentx.usda.gov.vcf
More information about the Austin
mailing list