Home » U++ TheIDE » U++ TheIDE: Compiling, Linking, Debugging of your packages » I keep getting the same "cannot open exe for writing" error...
|
|
|
|
Re: I keep getting the same "cannot open exe for writing" error... [message #50947 is a reply to message #50914] |
Mon, 14 January 2019 22:49 |
|
koldo
Messages: 3358 Registered: August 2008
|
Senior Veteran |
|
|
peterh wrote on Mon, 14 January 2019 11:31Now, if it happens only once a week this should not be a problem.
When I had the problem, it happened again and again.
I debugged simple programs without child processes.
And after the latest modification (DebugProcessStop) I had not a single problem and I did heavy repeated testing and I tried to provoke the problem.
It did not happen again here. Yes I agree.
Without changes you have to close TheIDE many times every day.
I do not know if the code I use is the best, as I do not know the root cause of the problem.
However, you should remember that TerminateProcess() does not terminate child process, so I call TerminateChildProcesses(hProcessId, 0); just before.
It uses dwProcessId from pdb.cpp, line 117:
hProcess = pi.hProcess;
hProcessId = pi.dwProcessId; // Added
mainThread = pi.hThread;
mainThreadId = pi.dwThreadId;
and TerminateChildProcesses() is implemented like this:
#include <TlHelp32.h>
Vector<DWORD> GetChildProcessList(DWORD processId) {
Vector<DWORD> child, all, parents;
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnap == INVALID_HANDLE_VALUE)
return child;
PROCESSENTRY32 proc;
proc.dwSize = sizeof(proc);
if (!Process32First(hSnap, &proc)) {
CloseHandle(hSnap);
return child;
}
do {
all << proc.th32ProcessID;
parents << proc.th32ParentProcessID;
} while(Process32Next(hSnap, &proc));
CloseHandle(hSnap);
child << processId;
int init = 0;
while (true) {
int count = child.GetCount();
if (init >= count)
break;
for (int cid = init; cid < count; ++cid) {
for (int i = 0; i < all.GetCount(); ++i) {
if (parents[i] == child[cid])
child << all[i];
}
}
init = count;
}
child.Remove(0);
return child;
}
void TerminateChildProcesses(DWORD dwProcessId, UINT uExitCode) {
Vector<DWORD> children = GetChildProcessList(dwProcessId);
for (int i = 0; i < children.GetCount(); ++i) {
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, children[i]);
TerminateProcess(hProcess, uExitCode);
CloseHandle(hProcess);
}
}
Best regards
Iñaki
|
|
|
|
|
|
Goto Forum:
Current Time: Sat May 04 10:06:29 CEST 2024
Total time taken to generate the page: 0.03198 seconds
|