19#define WAIT() { RUNLOG("<<<mutex.lock()") mutex.lock(); RUNLOG(">>>mutex.lock()") }
20#define POST() { RUNLOG("<<<mutex.unlock()") mutex.unlock(); RUNLOG(">>>mutex.unlock()") }
26 static bool KILL(
HANDLE handle)
28 BOOL bRet=TerminateProcess(handle, 0);
31 fprintf(stderr,
"brutally terminated by TerminateProcess\n");
33 return bRet?
true:
false;
35 static bool TERMINATE(
PID pid);
36 #define CLOSE(h) CloseHandle(h)
38 static DWORD WINAPI ZombieHunter(__in LPVOID lpParameter)
40 static DWORD WINAPI ZombieHunter(LPVOID lpParameter)
48 HANDLE* aHandlesVector =
nullptr;
49 pProcessVector->GetHandles(aHandlesVector, nCount);
53 WaitForMultipleObjects(nCount, aHandlesVector, FALSE, INFINITE);
54 delete [] aHandlesVector;
72 int ret=(close(h)==0);
78 int ret=!yarp::os::impl::kill(pid, signum);
131 RUNLOG(
"<<<GetExitCodeProcess(mHandleCmd, &status)")
132 bool ret=(::GetExitCodeProcess(
mHandleCmd, &status) && status==STILL_ACTIVE);
133 RUNLOG(
">>>GetExitCodeProcess(mHandleCmd, &status)")
146 fprintf(stderr,
"CLEANUP cmd %d\n",
mPidCmd);
182 HANDLE hkill=hZombieHunter;
183 hZombieHunter =
nullptr;
184 TerminateThread(hkill, 0);
197 fprintf(stderr,
"ERROR: maximum process limit reached\n");
205 HANDLE hkill=hZombieHunter;
206 hZombieHunter =
nullptr;
207 TerminateThread(hkill, 0);
214 hZombieHunter=CreateThread(0, 0, ZombieHunter,
this, 0, 0);
238 for (
int k=0; k<nKill; ++k)
240 fprintf(stderr,
"SIGNAL %s (%d)\n", aKill[k]->mAlias.c_str(), aKill[k]->mPidCmd);
241 aKill[k]->Signal(signum);
266 for (
int k=0; k<nKill; ++k)
268 fprintf(stderr,
"SIGNAL %s (%d)\n", aKill[k]->mAlias.c_str(), aKill[k]->mPidCmd);
269 aKill[k]->Signal(signum);
278void YarpRunInfoVector::GetHandles(
HANDLE* &lpHandles, DWORD &nCount)
282 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);
583 yarp::os::impl::kill(
mPidCmd, SIGTERM);
589 yarp::os::impl::kill(
mPidStdin, SIGTERM);
622 yarp::run::Run::sendMsg(msg,
mStdio);
633#define TA_SUCCESS_CLEAN 1
634#define TA_SUCCESS_KILL 2
639 TerminateParams(DWORD
id)
651BOOL CALLBACK TerminateAppEnum(HWND hwnd, LPARAM lParam)
653 TerminateParams* params=(TerminateParams*)lParam;
656 GetWindowThreadProcessId(hwnd, &dwID) ;
658 if (dwID==params->dwID)
661 PostMessage(hwnd, WM_CLOSE, 0, 0);
675bool TERMINATE(
PID dwPID)
681 hProc=OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, dwPID);
683 if (hProc ==
nullptr)
691 TerminateParams params(dwPID);
693 EnumWindows((WNDENUMPROC)TerminateAppEnum, (LPARAM)¶ms);
697 fprintf(stderr,
"%d terminated by WM_CLOSE (sending anyway CTRL_C_EVENT/CTRL_BREAK_EVENT)\n", dwPID);
703 fprintf(stderr,
"%d terminated by CTRL_C_EVENT/CTRL_BREAK_EVENT\n", dwPID);
706 GenerateConsoleCtrlEvent(CTRL_C_EVENT, dwPID);
707 GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, dwPID);
int SIGNAL(int pid, int signum)
int SIGNAL(int pid, int signum)
YarpRunInfoVector * mStdioVector
YarpRunCmdWithStdioInfo(std::string &alias, std::string &on, std::string &stdio, PID pidCmd, PID pidStdout, FDESC readFromPipeCmdToStdout, FDESC writeToPipeCmdToStdout, HANDLE handleCmd, bool hold)
FDESC mWriteToPipeStdinToCmd
FDESC mReadFromPipeCmdToStdout
FDESC mWriteToPipeCmdToStdout
FDESC mReadFromPipeStdinToCmd
int Signal(std::string &alias, int signum)
bool CleanZombie(int zombie)
static const int MAX_PROCESSES
YarpRunInfoVector * m_pStdioMate
YarpRunProcInfo * m_apList[MAX_PROCESSES]
bool IsRunning(std::string &alias)
bool Add(YarpRunProcInfo *process)
YarpRunProcInfo(std::string &alias, std::string &on, PID pidCmd, HANDLE handleCmd, bool hold)
virtual bool Signal(int signum)
virtual bool Clean(PID pid, YarpRunProcInfo *&pRef)
A simple collection of objects that can be described and transmitted in a portable way.
void fromString(const std::string &text)
Initializes bottle from a string.
Bottle & addList()
Places an empty nested list in the bottle, at the end of the list.
void clear()
Empties the bottle of any objects it contains.
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
A mini-server for performing network communication in the background.