Hi All,
I am spawning a process from a service. The spawned process hungs for
various reasons, (corrupted data, deadlock). I am expecting the process has
to complete the task with in the expected time limit, if it exceeds the
limit I want to terminate the process (no mercy or graceful, just terminate
the process).
The spawnng of the process, counting the time and termination of process all
done in C++. Some time I am not able to terminate the process, the error
message was "Access denied". I dont want this also happens. The program has
to terminate the process even, the process in any state. How to do that?
What security permissions I have to give?
Here is the code snippet of the teminate application,
=============== =============== =============== ============
static DWORD WINAPI TerminateApp( DWORD dwPID, DWORD dwTimeout )
{
HANDLE hProc ;
DWORD dwRet ;
// If we can't open the process with PROCESS_TERMINA TE rights,
// then we give up immediately.
hProc = OpenProcess(SYN CHRONIZE|PROCES S_TERMINATE, FALSE,
dwPID);
if(hProc == NULL)
{
return TA_FAILED ;
}
// TerminateAppEnu m() posts WM_CLOSE to all windows whose PID
// matches your process's.
EnumWindows((WN DENUMPROC)Termi nateAppEnum, (LPARAM) dwPID) ;
// Wait on the handle. If it signals, great. If it times out,
// then you kill it.
if(WaitForSingl eObject(hProc, dwTimeout)!=WAI T_OBJECT_0)
dwRet=(Terminat eProcess(hProc, 0)?TA_SUCCESS_K ILL:TA_FAILED);
else
dwRet = TA_SUCCESS_CLEA N ;
CloseHandle(hPr oc) ;
return dwRet ;
}
static BOOL CALLBACK TerminateAppEnu m( HWND hwnd, LPARAM lParam )
{
DWORD dwID ;
GetWindowThread ProcessId(hwnd, &dwID) ;
if(dwID == (DWORD)lParam)
{
PostMessage(hwn d, WM_CLOSE, 0, 0) ;
}
return TRUE ;
}
=============== =============== =============== ============
All suggestion appreciated.
Thanks
GTS
I am spawning a process from a service. The spawned process hungs for
various reasons, (corrupted data, deadlock). I am expecting the process has
to complete the task with in the expected time limit, if it exceeds the
limit I want to terminate the process (no mercy or graceful, just terminate
the process).
The spawnng of the process, counting the time and termination of process all
done in C++. Some time I am not able to terminate the process, the error
message was "Access denied". I dont want this also happens. The program has
to terminate the process even, the process in any state. How to do that?
What security permissions I have to give?
Here is the code snippet of the teminate application,
=============== =============== =============== ============
static DWORD WINAPI TerminateApp( DWORD dwPID, DWORD dwTimeout )
{
HANDLE hProc ;
DWORD dwRet ;
// If we can't open the process with PROCESS_TERMINA TE rights,
// then we give up immediately.
hProc = OpenProcess(SYN CHRONIZE|PROCES S_TERMINATE, FALSE,
dwPID);
if(hProc == NULL)
{
return TA_FAILED ;
}
// TerminateAppEnu m() posts WM_CLOSE to all windows whose PID
// matches your process's.
EnumWindows((WN DENUMPROC)Termi nateAppEnum, (LPARAM) dwPID) ;
// Wait on the handle. If it signals, great. If it times out,
// then you kill it.
if(WaitForSingl eObject(hProc, dwTimeout)!=WAI T_OBJECT_0)
dwRet=(Terminat eProcess(hProc, 0)?TA_SUCCESS_K ILL:TA_FAILED);
else
dwRet = TA_SUCCESS_CLEA N ;
CloseHandle(hPr oc) ;
return dwRet ;
}
static BOOL CALLBACK TerminateAppEnu m( HWND hwnd, LPARAM lParam )
{
DWORD dwID ;
GetWindowThread ProcessId(hwnd, &dwID) ;
if(dwID == (DWORD)lParam)
{
PostMessage(hwn d, WM_CLOSE, 0, 0) ;
}
return TRUE ;
}
=============== =============== =============== ============
All suggestion appreciated.
Thanks
GTS
Comment