22 #define WAIT() { RUNLOG("<<<mutex.lock()") mutex.lock(); RUNLOG(">>>mutex.lock()") }
23 #define POST() { RUNLOG("<<<mutex.unlock()") mutex.unlock(); RUNLOG(">>>mutex.unlock()") }
29 static bool KILL(
HANDLE handle)
31 BOOL bRet=TerminateProcess(handle, 0);
34 fprintf(stderr,
"brutally terminated by TerminateProcess\n");
36 return bRet?
true:
false;
38 static bool TERMINATE(
PID pid);
39 #define CLOSE(h) CloseHandle(h)
41 static DWORD WINAPI ZombieHunter(__in LPVOID lpParameter)
43 static DWORD WINAPI ZombieHunter(LPVOID lpParameter)
51 HANDLE* aHandlesVector =
nullptr;
52 pProcessVector->GetHandles(aHandlesVector, nCount);
56 WaitForMultipleObjects(nCount, aHandlesVector, FALSE, INFINITE);
57 delete [] aHandlesVector;
75 int ret=(close(h)==0);
81 int ret=!yarp::os::impl::kill(pid, signum);
134 RUNLOG(
"<<<GetExitCodeProcess(mHandleCmd, &status)")
135 bool ret=(::GetExitCodeProcess(
mHandleCmd, &status) && status==STILL_ACTIVE);
136 RUNLOG(
">>>GetExitCodeProcess(mHandleCmd, &status)")
149 fprintf(stderr,
"CLEANUP cmd %d\n",
mPidCmd);
185 HANDLE hkill=hZombieHunter;
186 hZombieHunter =
nullptr;
187 TerminateThread(hkill, 0);
200 fprintf(stderr,
"ERROR: maximum process limit reached\n");
208 HANDLE hkill=hZombieHunter;
209 hZombieHunter =
nullptr;
210 TerminateThread(hkill, 0);
217 hZombieHunter=CreateThread(0, 0, ZombieHunter,
this, 0, 0);
241 for (
int k=0; k<nKill; ++k)
243 fprintf(stderr,
"SIGNAL %s (%d)\n", aKill[k]->mAlias.c_str(), aKill[k]->mPidCmd);
244 aKill[k]->Signal(signum);
269 for (
int k=0; k<nKill; ++k)
271 fprintf(stderr,
"SIGNAL %s (%d)\n", aKill[k]->mAlias.c_str(), aKill[k]->mPidCmd);
272 aKill[k]->Signal(signum);
281 void YarpRunInfoVector::GetHandles(
HANDLE* &lpHandles, DWORD &nCount)
285 if (lpHandles) delete [] lpHandles;
442 FDESC readFromPipeCmdToStdout,
443 FDESC writeToPipeCmdToStdout,
473 std::string& stdioUUID,
477 FDESC readFromPipeStdinToCmd,
478 FDESC writeToPipeStdinToCmd,
479 FDESC readFromPipeCmdToStdout,
480 FDESC writeToPipeCmdToStdout,
537 fprintf(stderr,
"CLEANUP cmd %d\n",
mPidCmd);
543 fprintf(stderr,
"CLEANUP stdin %d\n",
mPidStdin);
549 fprintf(stderr,
"CLEANUP stdout %d\n",
mPidStdout);
575 yarp::os::impl::kill(
mPidCmd, SIGTERM);
581 yarp::os::impl::kill(
mPidStdin, SIGTERM);
612 yarp::run::Run::sendMsg(msg,
mStdio);
623 #define TA_SUCCESS_CLEAN 1
624 #define TA_SUCCESS_KILL 2
626 class TerminateParams
629 TerminateParams(DWORD
id)
641 BOOL CALLBACK TerminateAppEnum(HWND hwnd, LPARAM lParam)
643 TerminateParams* params=(TerminateParams*)lParam;
646 GetWindowThreadProcessId(hwnd, &dwID) ;
648 if (dwID==params->dwID)
651 PostMessage(hwnd, WM_CLOSE, 0, 0);
665 bool TERMINATE(
PID dwPID)
671 hProc=OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, dwPID);
673 if (hProc ==
nullptr)
681 TerminateParams params(dwPID);
683 EnumWindows((WNDENUMPROC)TerminateAppEnum, (LPARAM)¶ms);
687 fprintf(stderr,
"%d terminated by WM_CLOSE (sending anyway CTRL_C_EVENT/CTRL_BREAK_EVENT)\n", dwPID);
693 fprintf(stderr,
"%d terminated by CTRL_C_EVENT/CTRL_BREAK_EVENT\n", dwPID);
696 GenerateConsoleCtrlEvent(CTRL_C_EVENT, dwPID);
697 GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, dwPID);