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_TERMINATE rights,
// then we give up immediately.
hProc = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE,
dwPID);
if(hProc == NULL)
{
return TA_FAILED ;
}
// TerminateAppEnum() posts WM_CLOSE to all windows whose PID
// matches your process's.
EnumWindows((WNDENUMPROC)TerminateAppEnum, (LPARAM) dwPID) ;
// Wait on the handle. If it signals, great. If it times out,
// then you kill it.
if(WaitForSingleObject(hProc, dwTimeout)!=WAIT_OBJECT_0)
dwRet=(TerminateProcess(hProc,0)?TA_SUCCESS_KILL:T A_FAILED);
else
dwRet = TA_SUCCESS_CLEAN ;
CloseHandle(hProc) ;
return dwRet ;
}
static BOOL CALLBACK TerminateAppEnum( HWND hwnd, LPARAM lParam )
{
DWORD dwID ;
GetWindowThreadProcessId(hwnd, &dwID) ;
if(dwID == (DWORD)lParam)
{
PostMessage(hwnd, WM_CLOSE, 0, 0) ;
}
return TRUE ;
}
================================================== =======
All suggestion appreciated.
Thanks
GTS 5 3029
"GTS" <gt******@hotmail.com> wrote in message news:<O1**************@TK2MSFTNGP12.phx.gbl>... 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). ...
Try this.
HANDLE h = OpenProcess(PROCESS_TERMINATE,FALSE,dwId);
TerminateProcess(h,0);
sending a wm_close to a "hung" process does not really help much....
hth.
-Vinayak
Or a better idea would be to send WM_CLOSE, wait some time, then check to
see if the process still exists. If it does, then do TerminateProcess() as
a last resort.
"Vinayak Raghuvamshi" <vs************@hotmail.com> wrote in message
news:9a**************************@posting.google.c om... "GTS" <gt******@hotmail.com> wrote in message
news:<O1**************@TK2MSFTNGP12.phx.gbl>... 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). ...
Try this.
HANDLE h = OpenProcess(PROCESS_TERMINATE,FALSE,dwId); TerminateProcess(h,0);
sending a wm_close to a "hung" process does not really help much....
hth. -Vinayak
"JJ" <jj**@nospam.com> wrote in message news:Oh*************@TK2MSFTNGP10.phx.gbl... Or a better idea would be to send WM_CLOSE, wait some time, then check to see if the process still exists. If it does, then do TerminateProcess() as a last resort.
Isn't that what the original poster did?
He sends the windows of the process the WM_CLOSE, then does WaitForSingleObject on the process. If it times-out rather than
signals, he calls TerminateProcess.
--
Adam Clauss ca*****@tamu.edu
Could you check the process identity the service runs with?
If it's:
"local system" AND
"Allow service to interact with desktop" is enabled,
AND the spawned process has a windows message loop (message pump).
then posting ( WM_CLOSE ) should work.
However, this won't work If "Allow service to interact with desktop" is not
set, as you can't post/send messages from the interactive desktop your
"terminate" program runs in to the sandboxed services desktop/winstation
your spawned process runs in.
"TerminateProcess" will not work either, as the spawned process runs as
"local system" it can only be terminated by a process running as "local
system", even an administrator can't terminate such process.
Willy.
"GTS" <gt******@hotmail.com> wrote in message
news:O1**************@TK2MSFTNGP12.phx.gbl... 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_TERMINATE rights, // then we give up immediately. hProc = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, dwPID);
if(hProc == NULL) { return TA_FAILED ; }
// TerminateAppEnum() posts WM_CLOSE to all windows whose PID // matches your process's. EnumWindows((WNDENUMPROC)TerminateAppEnum, (LPARAM) dwPID) ;
// Wait on the handle. If it signals, great. If it times out, // then you kill it. if(WaitForSingleObject(hProc, dwTimeout)!=WAIT_OBJECT_0) dwRet=(TerminateProcess(hProc,0)?TA_SUCCESS_KILL:T A_FAILED); else dwRet = TA_SUCCESS_CLEAN ;
CloseHandle(hProc) ;
return dwRet ; }
static BOOL CALLBACK TerminateAppEnum( HWND hwnd, LPARAM lParam ) { DWORD dwID ;
GetWindowThreadProcessId(hwnd, &dwID) ;
if(dwID == (DWORD)lParam) { PostMessage(hwnd, WM_CLOSE, 0, 0) ; }
return TRUE ; }
================================================== =======
All suggestion appreciated.
Thanks
GTS
Sorry - I missed that.
"Adam Clauss" <ca*****@tamu.edu> wrote in message
news:O1*************@TK2MSFTNGP12.phx.gbl... "JJ" <jj**@nospam.com> wrote in message
news:Oh*************@TK2MSFTNGP10.phx.gbl... Or a better idea would be to send WM_CLOSE, wait some time, then check
to see if the process still exists. If it does, then do TerminateProcess()
as a last resort.
Isn't that what the original poster did? He sends the windows of the process the WM_CLOSE, then does
WaitForSingleObject on the process. If it times-out rather than signals, he calls TerminateProcess.
-- Adam Clauss ca*****@tamu.edu This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Earl Eiland |
last post by:
I'm running a PyWin program that executes another program using
subprocess.Popen(). Unfortunately, this other program isn't well
behaved, and frequently terminates without terminating its process....
|
by: Byron |
last post by:
I'm new to C# and threading, so hopefully this is a simple newbie question.
I have a form that is supposed to listen for network traffic on a given port
and decode and display any interesting...
|
by: Jerry |
last post by:
If a Windows User decides to kill a process or a separate Windows app calls Process.Kill(), is there any way that the process being killed can see what's going on before it dies? I have a Windows...
|
by: Adam Clauss |
last post by:
I have a C# Windows Service running as the NetworkService account because it
needs to access a network share.
As part of the service's initialization, I want the service to terminate, if
an...
|
by: lgbjr |
last post by:
Hi All,
I have a VB.NET app that, among other things, writes data to Excel. I am
having trouble getting the Excel process to terminate after I quit Excel. I
found an article related to this...
|
by: Lauren the Ravishing |
last post by:
Hi,
In ASP, is it absolutely necessary to set an object to Nothing after
being used?
set myObj = server.createObject("myDLL.myClass")
call myObj.useClass
set myObj = Nothing <--- can I...
|
by: SMichal |
last post by:
Hi. how can I terminate process which was started with cmd /c ? The Kill()
method terminates only that CMD.exe
string cdHome = @"C:\Temp\";
string localhost = "chsaXY";
string userName = "aaa";...
|
by: Phoe6 |
last post by:
Hi all,
Consider this scenario, where in I need to use subprocess to execute a
command like 'ping 127.0.0.1' which will have a continuous non-
terminating output in Linux.
# code
# This...
|
by: geoffbache |
last post by:
Hi all,
I've always wondered why os.kill isn't supported on Windows. I found a
discussion somewhere from 2006 about this so it seems others have
wanted it, but still nothing. So I have a...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: SueHopson |
last post by:
Hi All,
I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...
| |