Re: KILLING Processes in unix
- From: "Paul Lalli" <mritty@xxxxxxxxx>
- Date: 27 Oct 2006 07:42:41 -0700
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
.
- References:
- KILLING Processes in unix
- From: Perl Pra
- KILLING Processes in unix
- Prev by Date: Re: win32 services
- Next by Date: Re: Need to pull matched string plus a few additional bytes
- Previous by thread: KILLING Processes in unix
- Next by thread: win32 services
- Index(es):
Relevant Pages
|