Solved

How can I control process termination timeout ?

Posted on 1998-11-13
8
533 Views
Last Modified: 2013-12-03
Hi,

I am using NT4.0 and I have the following question regarding to process control.

1. When we stop a process from task manager, if this process fails to respond, after certain time, we get a dialog box saying something like "wait..." or "End task", etc. How can we control this timeout ? I guess if we choose EndTask, NT will call TerminateProcess() to kill the process. But in some case, the process will still hang over there. Any way to handle this problem ?

2. When we stop a service from SCM, again, we will get a dialog box complaining the NT service is not responding in a certain time. How can we control this timeout ?

3. When we "Shutdown the computer", there is a certain timeout again. How can we control that ? Also, from a program, how can I issue a Shutdown the computer command ?

Any help is greatly appreciated.


Mike


0
Comment
Question by:mikechen
8 Comments
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
I don't know if you can control the timeout times of the task manager or of SCM (whatever this is...) or of the explorer's shutdown. Perhaps there are some registry settings, but I don't know them...
However, if you use TerminateProcess yourself, there'll be no delay. If the process then still hangs, you can't do nothing more. But in most most most cases TerminateProcess should work. Though, it's a very unkind way of ending processes, since the dlls of the terminated process have no chance to gracefully shut down.
I'm not so sure about the services. But AFAIK, services are just specific applications, so it will be the same as above...
To shutdown the computer from your program, use ExitWindowsEx(...). There will be no delay.

Regards, Madshi.
0
 

Author Comment

by:mikechen
Comment Utility
Thank you for your response, Madshi.

Actually, I know the terminate timeout of a service can be controlled. And I know the terminate timeout of the whole system is set in one of the registry key. I just forgot the key in the registry.

So anybody can give me some idea ?

Thanks,

Mike

0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Usually service's timeouts aer controlled by the service itself calling 'SetServiceStatus()' and setting the 'dwWaitHint' member of the 'SERVICE_STATUS' structure to the appropriate value (if the service reads this value from the registry, all is fine for you, but i usually hard-code this ;-). And, if you 'close' a process from the task manager, i primarily sends a 'WM_CLOSE' using 'SendMessageTimeout()' (if this times out, you'll get the 'not responding' dialog. 'Terminating' a process from the TM indeed means that it uses 'TerminateProcess()', giving the process no time to interact...
0
 

Author Comment

by:mikechen
Comment Utility
Thanks for your comment, jkr.

How about the whole system ? Does anybody know the registry ?

Thanks,

Mike

0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 15

Accepted Solution

by:
NickRepin earned 150 total points
Comment Utility
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\WaitToKillServiceTimeout

HKEY_USERS\.DEFAULT\Control Panel\Desktop\WaitToKillAppTimeout

HKEY_USERS\.DEFAULT\Control Panel\Desktop\HungAppTimeout

Little descriptions:

HungAppTimeout     REG_SZ

Range: Milliseconds (msec)

Default: 5000

Determines how long the system waits for user processes to end in response to the End Task button command in Task Manager. If this threshold is exceeded, the End Task dialog box appears stating that the process did not respond or, if AutoEndTasks is enabled, the system ends the process automatically.

WaitToKillAppTimeout     REG_SZ

Range: Milliseconds

Default: 20000

Determines how long the system waits for user processes to end after the user attempts to log off or to shut down Windows NT.  If this threshold is exceeded, the End Task dialog box appears stating that the process did not respond or, if AutoEndTasks is enabled, the system ends the process automatically.


AutoEndTasks     REG_SZ    

Range: 0 or 1

Default: 0 (disabled)

Determines whether user processes are ended automatically when the user logs off or stops Windows NT. If the value of this entry is 1 (or other than 0), processes are ended automatically. If it is set to 0, the system waits until the process ends and, if the process exceeds the timeout threshold (HungAppTimeout), the End Task dialog box appears stating that the application cannot respond to the End Task request.


0
 

Author Comment

by:mikechen
Comment Utility
Thank you for your response, NickRepin.

I remember there is another registry value controls the shutdown timeout of the whole system. I am not sure whether it is .

\HKEY_LOCAL_MACHINE\SYSTEMS\CurrentControlSet\Control\Windows\ShutdownTime  

Do you know how to interpret this value ?

Thanks again,

Mike
0
 
LVL 15

Expert Comment

by:NickRepin
Comment Utility
Its just a shutdown time. :)
The time when NT was turned off. In FILETIME struct.

If you are talking about the timeout for 'end task' request while shutdown, its exactly the same as for HungAppTimeout and controlled by this registry key. See description of AutoEndTask in my answer.

0
 

Author Comment

by:mikechen
Comment Utility
Thank you, NickRepin.

Mike

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now