2

I have a mixed process with native and managed code, running on Windows server 2003.

When I kill my process from within process explorer it goes into a state of 100% cpu and stays like that for a while (sometimes even 10 minutes) before going away. During this time I cannot "kill" it or do anything else.

What exaclty happens to a process when I kill it via process via process explorer's kill? I believe this does not call any destructors, so what could be causing such cpu usage?

Thanks, Dan

DanJ
  • 3,435
  • 3
  • 33
  • 44
  • 1
    He said `Windows server 2003`. – Jim Oct 17 '09 at 17:19
  • Sorry, missed that, thanks. Do you get the same behavior with other tools like kill.exe from the resource kit, taskkill.exe with the /F option or pskill.exe? – Dirk Vollmar Oct 17 '09 at 17:23
  • 1
    Just to clarify, when you exit the program gracefully it does not exhibit this same high CPU behavior? – mpeterson Oct 17 '09 at 18:32
  • Thanks for all the comments and ideas. I do get the same behavior using all of the various kill/exit methods. Using Process Explorer I'm not able to show the thread stack after I kill the process. The 100% CPU time is kernel time, so I think the resources deallocation is a good place to start looking. I will post another comment when I figure this out. – DanJ Oct 24 '09 at 07:58

5 Answers5

1

Try it using End Process (on Process tab) of Task Manager instead, and try whether there's a difference if you choose Kill Process Tree on either Task Manager or Winternal's Process Explorer, however I doubt it'll help.

The process is supposed to be killed (almost) instantly, however, there are some sneaky ways to stick around. If you wrote your own application, I assume that isn't the case. It is more then likely that other processes don't like yours being taken away. Set Process Monitor on quick refresh speed and sort the cpu column. You should now see which process is causing the 100% issue. Most likely: system.

In the event that you use a lot of memory, esp. when it's overall more than the physical memory, the system will reorganize (i.e., move memory from disk back to physical memory). A similar behavior occurs (up until freezing my system) when I kill Firefox after I open 500+ tabs, occupying 1.5GB memory. This behavior (slowly reorganizing memory) has improved with later versions of Microsoft Windows.

UPDATE: internally, proc expl. calls TerminateProcess (amongst others), which force-closes all handles and threads. The MSDN API ref says "TerminateProcess initiates termination and returns immediately. This stops execution of all threads within the process and requests cancellation of all pending I/O. The terminated process cannot exit until all pending I/O has been completed or canceled.". Which means so much as: your I/O can block this process (though I wonder how it can bring your process to 100%, I/O usually doesn't do that).

Abel
  • 56,041
  • 24
  • 146
  • 247
  • I'm sure it is my process that is taking 100% cpu, and not some other process. The memory reorg. sounds interesting - I will look into this. Thanks – DanJ Oct 17 '09 at 17:48
1

Obviously something is trying to continue running, which is causing the hang/deadlock condition you are seeing. I could attempt to explain how to use some tools to try and find out what is happening, but I should probably just defer you to the master... Tess - Lab on High CPU Hang

I was able to use the methods she describes to figure out issues with my own applications.

mpeterson
  • 1,672
  • 12
  • 15
0

If you have several threads, or other resources that weren't released then it may be trying to wait for everything to be freed before the application is killed.

When your application is killed, ideally it is expected that all resources that are used will be freed, but that is why you should ensure you implement the IDispose interface, to help with this, otherwise you may find that some file is open that can't be re-opened, and your only option is to reboot.

Does this happen when you try to kill other applications, or just this one?

You may want to simplify your program, or try to kill it before it uses too many resources, and see if you can determine at what point you will encounter this problem, and then you may have a better idea what you did that is causing this behavior.

James Black
  • 41,583
  • 10
  • 86
  • 166
  • if an application is killed this way, IDisposable objects aren't called anymore, all recources (object handles) are force-closed. – Abel Oct 17 '09 at 18:35
0

Could you look at the threads in Process Explorer? See what's running and particularly what's taking up 100% CPU. See if you can find the call stack and isolate the specific thread or even function. Post the answer here if you can!

Ori Osherov
  • 484
  • 1
  • 6
  • 15
0

My psychic debugger is that you had a lot of resources still allocated (i.e. file/reg handles, win32k objects, etc) and the kernel is cleaning them up. When you use Process Explorer to crack into the app, does the resource usage look high?

Ana Betts
  • 73,868
  • 16
  • 141
  • 209
  • Resource usage looks normal, but it looks like I'm missing something. Memory, handles, threads, all look ok. Any other resources that I should look for? – DanJ Oct 24 '09 at 08:30