|
-
May 26th, 2011, 05:56 AM
#1
Forcing a hung/busy windows service to exit
Hello,
Facing an issue with a windows service in client's production environement.
They complain the service gets hanged up and they can not shut it down or fail to kill the process. This is their production envoirnment and they can not frequently restart their machine to do that..
I have observed the log file on disk that our service creates,
based on that what I've observed is
When user tries to stop the service from the service panel, the following function gets the control and I hope we can force the service in the following handler to exit even if it is hung somewhere else ...
Please advise,
Thank you,
Ahmed
// some where in code we set this handler using
hServiceStatus = RegisterServiceCtrlHandler(szExeName,(LPHANDLER_FUNCTION)controlHandler);
// Here is the actual handler
void controlHandler(DWORD request)
{
switch(request)
{
case SERVICE_CONTROL_STOP:
serviceStatus.dwWin32ExitCode = 0;
serviceStatus.dwCurrentState = SERVICE_STOPPED;
SetServiceStatus (hServiceStatus, &serviceStatus);
LOG(LOG_WARN, "SERVICE CONTROL", FormatString("Service Stopped"));
// our close open sockets etc..
// Advise Some code to force exit service as it may be hung else where for indefinite time
return;
case SERVICE_CONTROL_SHUTDOWN:
serviceStatus.dwWin32ExitCode = 0;
serviceStatus.dwCurrentState = SERVICE_STOPPED;
SetServiceStatus (hServiceStatus, &serviceStatus);
LOG(LOG_WARN, "SERVICE CONTROL", FormatString("Service Shutdown"));
// Advise Some code to force exit service as it may be hung else where for indefinite time
return;
default:
break;
}
// Report current status
SetServiceStatus (hServiceStatus, &serviceStatus);
return;
}
He is not strong and powerful, who throws people down, but he is strong who withholds himself from anger
MyWeb
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|