Killing a process under Windows NT/2K

Tim Peters tim.one at comcast.net
Fri Apr 26 21:17:04 EDT 2002


[Tavis Rudd, on
]       win32process.TerminateProcess(handle, 1)

> Is this a hard kill (like kill -9)

Yes.  Quoth the docs:

    The TerminateProcess function is used to unconditionally cause a
    process to exit.  Use it only in extreme circumstances.  The state
    of global data maintained by dynamic-link libraries (DLLs) may be
    compromised if TerminateProcess is used rather than ExitProcess.

    TerminateProcess causes all threads within a process to terminate,
    and causes a process to exit, but DLLs attached to the process are
    not notified that the process is terminating.

> or a soft kill that triggers the appropriate signal handler
> inside the process?

This is Windows -- Unixish signals aren't popular there.  So, sure, it
triggers all the signal handlers a typical Windows program has <wink>.

Windows doesn't offer a safe-in-all-cases way for forced external
termination.  See, e.g.,

     http://www.wd-mag.com/articles/1999/9907/9907c/9907c.htm

for a discussion of some of the issues.  The heart of the method used there
is to create a new thread inside the process to be killed, and have it call
the orderly ExitProcess() from within the process to be killed.  However,
the CreateRemoteThread() API needed to do this didn't exist before Win98.






More information about the Python-list mailing list