Greetings PMonks,

I need a cleaner method than Win32::Process::Kill() to terminate a (non-perl) process I have spawned out of a perl script. It's a server that I want to start up, do some tests on and then cleanly shut down. I'm doing all of the management of this process with Win32::Process. The problem with this module's Kill() method is that it ultimately maps to win32's TerminateProcess(). This is bad because this blows the process out of the water, so to speak, without letting it clean up after itself. According to all the documentation I've read this can lead to possible problems with dll's used by the process, because it doesn't let the process properly disconnect from the dll's it is using. In the case of our server it also doesn't allow for flushing of the log buffer so we miss some diagnostic information.

It looks like the solution would be use the win32 GenerateConsoleCtrlEvent() to send a ctrl-c event to the process, but there doesn't seem to be a good way within the Perl world to access this function in the context I'm dealing with. Win32::Console does seem to implement some kind of access to this function, but the documentation there seems to indicate that it can only be used to send events to yourself (Not 100% sure of this as the documentation is rather limited).

This node seems to point to a way of using GenerateConsoleCtrlEvent using Win32::API, but this seems kludgy at best.

Does anyone know of a less kludgy solution to this problem?

--DrWhy

"If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."


In reply to How do I cleanly kill a spawned process on Win32. by DrWhy

Title:
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, details, 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, summary, 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.