Jump to content
  • Advertisement
Sign in to follow this  
bjogio

process termination

This topic is 4832 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've some coding skill regarding Linux handling over processes and thread. Now I need to work in a game in m/Windows (.+)/ plaform and I'm a little confused regarding process kill. I've already managed WM_CLOSE, WM_QUIT, WM_WHATEVER event together with the atexit function and eventually signal(SIG_TERM and other), ctrl+C etc. etc. and everything runs well with my program that release all resource in a good way at process exceptional exit. But now I need to manage the evil: ctrl+alt+canc -> task manager -> (terminate process| terminate process structure). There is a way to manage this event? When I kill a process in this way NO signal is raised, NO atexit function are called, NO structured exception is raised, NO exception, well NOTHING seems to happen in the killed process so I can't do any resouce collect and I have memory leak. Do Ms has implemented this danger option without any form of notification to the killed process? I can't believe this. Am I missing something?

Share this post


Link to post
Share on other sites
Advertisement
Are you sure you have a memory leak? When a process is terminated from the process list, Windows deallocats the chunk(s) of memory requested by the process, and removes it from the process "queue" or tree, or whatever it uses, including all threads which are associated with it. If you're using malloc or new, then that memory is allocated on the heap, and the entire heap should be "removed" when Windows deallocates the memory. If you're allocating a new heap through Windows, it should still be removed from memory, though I'm not sure about it.

Nevertheless, I wouldn't be too worried about any leak resulting from this form of shutdown. This is an emergency shutdown, usually when your program locks up or when people get fed up of waiting, and the End Task button (which I think does send a WM_QUIT message) doesn't work, at least in a timely manner. As such, people who use this should be aware that it could adversely affect system performance. Most users don't even know that little tab exists, or how to use it anyway. ^_^

Theoretically, you should be able to detect it using Windows Hooks, but that would probably be more work than it's worth. Plus, I can't tell you how to do it either.

Share this post


Link to post
Share on other sites
But what about function that are called at program exit? Something like flush the file or save setting? These will never be called.

Share this post


Link to post
Share on other sites
If somebody calls TerminateProcess on you then you're dead and you get no chance to handle things. The OS will clean up your memory, close your handles, etc, etc so you don't need to worry about memory leaks. TerminateProcess is basically the last ditch effort to get the process to go away after posting window messages and ctrl-c, etc have failed.

The only place you might run into trouble is if your program leaves turds around like flag files or temporary data in the registry or something. The answer to those is simple - don't do that. The other possible gotcha is if you're talking over the network via a UDP "connection" but in that case you should have some sort of timeout mechanism on the remote machine anyway.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!