Re: KILLING Processes in unix



Perl Pra wrote:
I need to kill java processes in Unix and windows both based on OS check.

here is my code

use Switch;

my $UKILLSTR="ps -ef |grep java | grep -v grep|kill -9 `awk '{print $2}'`

If you'd enabled warnings, Perl would have told you what you'd done
wrong here. Please start doing so in the future.

$2 is a valid Perl variable, that you're trying to interpolate in your
double quoted string. If you want to pass an actual $ followed by 2 in
to your shell command, backslash the $.

";(this command work if i put in command prompt of the linux box )
my $UKILLSTR1="
my $WKILLSTR="taskkill /IM java.exe /F";
my $OS=$^O;


switch ($OS) {

case "MSWin32" { system("$UKILLSTR"); }
case "LINUX" { system("$UKILLSTR");}
else { print "INVALID OS \n";}

}


I don't believe for a second that's your real code, as you never used
$WKILLSTR, and are executing the same command for either OS. Please
copy and paste your code, do not retype!

and Is there any way in perl to kill processes independent of OS .. If there
is hwo can i do that ?

I have no idea if/how it works in windows, but the correct way in Unix
is via the kill() function.

Read perldoc perlport to see if it has anything on kill() for Windows.
I honestly don't know.

Paul Lalli

.



Relevant Pages

  • FAQ 7.22 How do I create a switch or case statement?
    ... If one wants to use pure Perl and to be compatible with Perl versions ... Here's a simple example of a switch based on pattern matching, ... The perlfaq-workers, a group of volunteers, maintain the perlfaq. ... operating system or platform, so please include relevant details for ...
    (comp.lang.perl.misc)
  • FAQ 7.23 How do I create a switch or case statement?
    ... If one wants to use pure Perl and to be compatible with Perl versions ... Here's a simple example of a switch based on pattern matching, ... The perlfaq-workers, a group of volunteers, maintain the perlfaq. ... operating system or platform, so please include relevant details for ...
    (comp.lang.perl.misc)
  • FAQ 7.23 How do I create a switch or case statement?
    ... If one wants to use pure Perl and to be compatible with Perl versions ... Here's a simple example of a switch based on pattern matching, ... The perlfaq-workers, a group of volunteers, maintain the perlfaq. ... operating system or platform, so please include relevant details for ...
    (comp.lang.perl.misc)
  • Re: TCL vs. Perl
    ... I don't understand why Perl doesn't have a 'switch' ... goto END; ... A 'C' switch/case statement is something different. ...
    (comp.lang.perl.misc)
  • Re: passing variable to sub - $_=SendMessage
    ... sub RxMsg { ... buf - foo ... This is not Perl as I know it... ... Move it outside the switch (or the ...
    (comp.lang.perl.misc)