in reply to Re: Kill java processes on Windows server
in thread Kill java processes on Windows server

Hi got this error when i did that The handle is invalid at kill_process.pl line 16. here is the code used
use strict; use Win32::Process::Info; use Win32::Process; use Data::Dumper; Win32::Process::Info->Set(variant=>'WMI'); my $pi = Win32::Process::Info->new(); my $exitcode; for($pi->ListPids){ my ($info) = $pi->GetProcInfo($_); if($info->{Caption} =~ m/^java.exe$/i){ if($info->{WorkingSetSize} ge '100000000'){ my $obj; print "Kiling Java Process\n"; my $pid = $info->{ProcessId}; Win32::Process::Open($obj,$pid,1); $obj->Kill(0) or die $^E; } } }

Replies are listed 'Best First'.
Re^3: Kill java processes on Windows server
by BrowserUk (Patriarch) on Jan 22, 2010 at 15:52 UTC

    Then I suspect that you do not have the appropriate permissions to kill those java processes.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      I am logged in as admin on that box while running the script.
      I am running the script as admin of that box. Not sure why it wont kill

        Can you kill the process manually using the Task Manager?

      Yes i am able to kill it manually

        Have you tried?:

        Win32::Process::KillProcess($pid, $exitcode)

        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        Also, you should be checking that the Open() has succeeded:

        Win32::Process::Open($obj,$pid,1) or die "Failed to open $pid: $^E";

        I was ignoring this possibility as I thought that you would be getting an "$obj uninitialised" error had the called failed, but unfortunately, the author chose to return 0 instead of undef.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.