in reply to Kill a process in perl windows and proceed only if it killed the process

Will KillProcess return true on success? what this exit code means will that tells me it was a success? How can I check with an exitcode or returnCode and make sure a process actually killed?

There is absolutely no reason to loop!

If you have the appropriate permissions to kill the process; the single call to KillProcess() will kill it. And if you do not; retrying won't help.

Calling the Wait() method will ensure that it has actually died before your program continues; but be aware that if -- for example -- the process had just initiated a synchronous read request -- say a blocking tcp read -- to device or server that was slow, broken or non-existent, then you might have to wait quite some time before the process actually goes away and the Wait() completes. (For example: many tcp timeouts default to 900 seconds; some default DB server timeouts are even longer!)

The bottom line is: for most purposes, simply getting a non-zero return code from KillProcess() is enough to allow you to proceed.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
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.

The start of some sanity?

  • Comment on Re: Kill a process in perl windows and proceed only if it killed the process
  • Download Code

Replies are listed 'Best First'.
Re^2: Kill a process in perl windows and proceed only if it killed the process
by Anonymous Monk on Jul 24, 2012 at 15:50 UTC
    I tried the killProcess call followed by wait() call that BrowserUK suggested, but when I tried Win32::Process::Wait it gives me this error message- 'Usage:Win32::Process::Wait(cP, timeout)'
    what is 'cP' argument means?
    $^E=0; Win32::Process::KillProcess($pid, 111) or warn $^E; Win32::Process::Wait(INFINITE);
    Thanks,
    Peter
      what is 'cP' argument means?

      You are calling Win32::Process::Wait() as a subroutine; you should be calling it as a method.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      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.

      The start of some sanity?

        sorry, I didn't understand.
        I get the processids of the applications running on a processing node and I just want to kill it and wait for that process to be killed. I am not creating the process using Win32::Process::Create().