Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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?
  • If KillProcess() returns non-zero; the process *will* terminate.

    The process cannot prevent it.

  • If it returns zero; it probably means you do not have the privileged to kill it.

    Check $^E for the reason it failed.

  • The exitcode parameter to KillProcess() is an input parameter; not an output parameter.

    It is the value that will be returned to any process that calls GetExitProcess() after it has been killed.

  • If you absolutely need to know that the process is dead; as opposed to knowing that it will die at some point in the near future:

    Follow the KillProcess() call with a call to the Wait() method.

    When that returns the process is actually dead,

  • As stated above, if KillProcess() returns true, the process *will die*; but if you need to know if it was you that killed it:

    Pass an unusual exitcode (eg. not 1 or 0 or -1; say 13579 or your favorite sub 2**16 prime number).

    And then call the GetExitCode() method and compare. Not that you would be able to do anything about it if it wasn't.

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?

In reply to Re: Kill a process in perl windows and proceed only if it killed the process by BrowserUk
in thread Kill a process in perl windows and proceed only if it killed the process by Anonymous Monk

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (5)
    As of 2018-03-23 07:50 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (288 votes). Check out past polls.