Re: Win32 TerminateProcess problem

Jim Tilander <[email protected]>
Newsgroups gmane.games.devel.sweng
Message-ID <[email protected]>
TerminateProcess does leak resources, on all NT kernels. Yes, that includes
whatever you run. I'm not even including Win98 or lesser, they are not even
production "OS"s anyways. For anyone curious, you should first read the man
page on TerminateProcess (
http://msdn.microsoft.com/en-us/library/ms686714(VS.85).aspx ... yes RTFM).
This is not a "theoretical" case, if you have any DLLs attached (and you
most probably will for any but the most trivial of applications) you *will*
leak resources. We had this in our pipeline and it took blood sweat and
tears to track this one down (happend during distribution of our "simple"
tools, and it leaked every time things timed out. Over the course of
hundreds of thousands of these builds machines on the network quickly
experience slowdowns and "random" crashes).

A quick google on "TerminateProcess" shows this as the second hit:
http://www.drdobbs.com/windows/184416547?pgno=1  for the doubter.

/j

On Wed, Feb 3, 2010 at 6:57 PM, Jon Watte <[email protected]> wrote:

> > It is documented to leak resources
>
> Only on Windows 98. Because Windows NT/XP/Vista/7 has a real kernel, a
> process that goes away, goes away -- including all its resources. It's
> almost like a real OS that way :-) Of course, if you have bad drivers who
> don't deal with the kernel suddenly cancelling outstanding I/O and closing
> the driver abruptly, there's not much you can do about that.
>
> By contrast, TerminateThread is bad to call if you intend to keep running
> within the process, because for all you know, the thread might be in the
> middle of memory allocation, holding the heap lock, which means you can't
> really get much else done in the process if that thread were to just stop...
>
> Sincerely,
>
> jw
>
> --
> Americans might object: there is no way we would sacrifice our living
> standards for the benefit of people in the rest of the world. Nevertheless,
> whether we get there willingly or not, we shall soon have lower consumption
> rates, because our present rates are unsustainable.
>
>
>
> On Wed, Feb 3, 2010 at 6:33 PM, Emil Dotchevski <[email protected]>wrote:
>
>> On Wed, Feb 3, 2010 at 6:13 PM, Jim Tilander <[email protected]> wrote:
>> >
>> > For what it is worth, TerminateProcess is a terrible thing to call. It
>> is
>> > documented to leak resources, and it will have a real impact on your
>> system
>> > performance, all from making it slowly slower to just making it unusable
>> in
>> > a couple of minutes.
>>
>> Are you sure you're not talking about TerminateThread? Could you point
>> me to the place in the documentation that specifies that
>> TerminateProcess may leak resources?
>>
>> > The "best" way I'm aware of is to start a remote thread
>> > in the process you want to kill and call exit from that thread (which
>> will
>> > allow the process cleanup to run).
>>
>> This is incorrect. Exiting from a process internally calls
>> TerminateThread on all but the thread that calls it, thus it isn't
>> safer than terminating the process from the outside. In fact it is
>> probably less safe because you're running code in a process that's
>> dying, as opposed from another (healthy) process.
>>
>> It's also worth pointing out that once exit is called, all thread
>> synchronization primitives for that process stop working properly; you
>> can only imagine what happens with all the shared states they were
>> protecting. :)
>>
>> Emil Dotchevski
>> Reverge Studios, Inc.
>> http://www.revergestudios.com/reblog/index.php?n=ReCode
>> _______________________________________________
>> Sweng-Gamedev mailing list
>> [email protected]
>>
>> http://lists.midnightryder.com/listinfo.cgi/sweng-gamedev-midnightryder.com
>>
>
>
> _______________________________________________
> Sweng-Gamedev mailing list
> [email protected]
> http://lists.midnightryder.com/listinfo.cgi/sweng-gamedev-midnightryder.com
>
>


-- 
Introspection is just a ladder for people who have dug them an object
oriented hole.

_______________________________________________
Sweng-Gamedev mailing list
[email protected]
http://lists.midnightryder.com/listinfo.cgi/sweng-gamedev-midnightryder.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.