I've been working on a script that will allow me to
kill a certain program using the program's PID.

#!/usr/bin/perl -w
use strict;

sub findPID {
        if (my $PID = `pgrep PROGRAM`) {
                return $PID;
        } else {
                return 0;
        }
}

my $fPID = &findPID();
if ($fPID == 0) {
        print "PROGRAM: $fPID\n";
        print "No PROGRAM.\n";
} else {
        print "PROGRAM: $fPID\n";
        print "killing PROGRAM\n";
        kill 1,$fPID;
}

my $fPID1 = &findPID();
unless ($fPID1 == 0) {
        print "PROGRAM: $fPID1\n";
        print "killing PROGRAM with signal 9\n";
        kill 9,$fPID1;
}


Here are the results:

[EMAIL PROTECTED]:/imports/home/cspears/Documents/Dev>
PROGRAM &
[1] 7890
[EMAIL PROTECTED]:/imports/home/cspears/Documents/Dev>
./killProgram
PROGRAM: 7890

killing PROGRAM
PROGRAM: 7890

killing PROGRAM with signal 9
[1]+  Hangup                  framecycler
[EMAIL PROTECTED]:/imports/home/cspears/Documents/Dev>
./killPROGRAM
PROGRAM: 0
No PROGRAM.

While the script works in that the program ultimately
dies, the portion that checks to see if the kill
command worked the first time seems to not be working.
 Any advice?


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to