[Python-Dev] RE: how to kill process on Windows started with os.spawn?

Tim Peters tim.one@comcast.net
Mon, 02 Dec 2002 13:35:58 -0500


[Tim]
>> Yes.  On Windows it wants a handle, because that's what spawn*()
>> returns on Windows.  But, again, Windows processes aren't intended
>> to be killed externally.

[martin@v.loewis.de]
> That sounds like FUD.

Argue w/ Microsoft -- you've read their docs.

> Why is it that processes aren't intended to be killed? Because the
> assassin can't know what state the process is in, so the process
> may not complete correctly?

It's easy to find long articles about the dangers on the net.  Here's one I
don't think has been posted before:

    http://tinyurl.com/35o6

> This is a general problem with killing, not specific to Windows, and
> it never stopped a killer.
>
> Or can you crash the operating system or the killer process by
> terminating some other process?

It's certainly possible to crash Win9x by killing processes, and easy to
hang the killer process (indeed, I have four shareware "process killers" on
my home box, as no single one of them is able to kill everything --
sometimes I have a hung process, and three hung process killers trying to
nuke it!  Win98SE generally becomes too unstable to continue running at that
point.).

>> Why do you need to kill a process externally?  For example, why
>> can't you make "please stop now" a part of the protocol, so that a
>> process can terminate itself gracefully when told to?

> Because the process did not respond to the protocol. Should I kill it
> anyway and send a bug report to Microsoft?

The questions were addressed to Skip about his specific app.  It sounded to
me like he wanted to kill() routinely, instead of pursuing a clean shutdown.

    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.

because TerminateProcess doesn't notify attached DLLs of process
termination -- it's not solely the killed process's state that can get
hosed.