mirror of
https://github.com/pocoproject/poco.git
synced 2025-11-25 06:36:37 +01:00
@@ -217,6 +217,15 @@ public:
|
|||||||
/// Waits for the process specified by handle to terminate
|
/// Waits for the process specified by handle to terminate
|
||||||
/// and returns the exit code of the process.
|
/// and returns the exit code of the process.
|
||||||
|
|
||||||
|
static bool isRunning(const ProcessHandle& handle);
|
||||||
|
/// check if the process specified by handle is running or not
|
||||||
|
///
|
||||||
|
/// This is preferable on Windows where process IDs
|
||||||
|
/// may be reused.
|
||||||
|
|
||||||
|
static bool isRunning(PID pid);
|
||||||
|
/// Check if the process specified by given pid is running or not.
|
||||||
|
|
||||||
static void kill(ProcessHandle& handle);
|
static void kill(ProcessHandle& handle);
|
||||||
/// Kills the process specified by handle.
|
/// Kills the process specified by handle.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -66,6 +66,8 @@ public:
|
|||||||
const EnvImpl& env);
|
const EnvImpl& env);
|
||||||
static void killImpl(ProcessHandleImpl& handle);
|
static void killImpl(ProcessHandleImpl& handle);
|
||||||
static void killImpl(PIDImpl pid);
|
static void killImpl(PIDImpl pid);
|
||||||
|
static bool isRunningImpl(const ProcessHandleImpl& handle);
|
||||||
|
static bool isRunningImpl(PIDImpl pid);
|
||||||
static void requestTerminationImpl(PIDImpl pid);
|
static void requestTerminationImpl(PIDImpl pid);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ public:
|
|||||||
static int waitImpl(PIDImpl pid);
|
static int waitImpl(PIDImpl pid);
|
||||||
static void killImpl(ProcessHandleImpl& handle);
|
static void killImpl(ProcessHandleImpl& handle);
|
||||||
static void killImpl(PIDImpl pid);
|
static void killImpl(PIDImpl pid);
|
||||||
|
static bool isRunningImpl(const ProcessHandleImpl& handle);
|
||||||
|
static bool isRunningImpl(PIDImpl pid);
|
||||||
static void requestTerminationImpl(PIDImpl pid);
|
static void requestTerminationImpl(PIDImpl pid);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -68,6 +68,8 @@ public:
|
|||||||
const EnvImpl& env);
|
const EnvImpl& env);
|
||||||
static void killImpl(ProcessHandleImpl& handle);
|
static void killImpl(ProcessHandleImpl& handle);
|
||||||
static void killImpl(PIDImpl pid);
|
static void killImpl(PIDImpl pid);
|
||||||
|
static bool isRunningImpl(const ProcessHandleImpl& handle);
|
||||||
|
static bool isRunningImpl(PIDImpl pid);
|
||||||
static void requestTerminationImpl(PIDImpl pid);
|
static void requestTerminationImpl(PIDImpl pid);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,8 @@ public:
|
|||||||
const EnvImpl& env);
|
const EnvImpl& env);
|
||||||
static void killImpl(ProcessHandleImpl& handle);
|
static void killImpl(ProcessHandleImpl& handle);
|
||||||
static void killImpl(PIDImpl pid);
|
static void killImpl(PIDImpl pid);
|
||||||
|
static bool isRunningImpl(const ProcessHandleImpl& handle);
|
||||||
|
static bool isRunningImpl(PIDImpl pid);
|
||||||
static void requestTerminationImpl(PIDImpl pid);
|
static void requestTerminationImpl(PIDImpl pid);
|
||||||
static std::string terminationEventName(PIDImpl pid);
|
static std::string terminationEventName(PIDImpl pid);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -72,6 +72,8 @@ public:
|
|||||||
const EnvImpl& env);
|
const EnvImpl& env);
|
||||||
static void killImpl(ProcessHandleImpl& handle);
|
static void killImpl(ProcessHandleImpl& handle);
|
||||||
static void killImpl(PIDImpl pid);
|
static void killImpl(PIDImpl pid);
|
||||||
|
static bool isRunningImpl(const ProcessHandleImpl& handle);
|
||||||
|
static bool isRunningImpl(PIDImpl pid);
|
||||||
static void requestTerminationImpl(PIDImpl pid);
|
static void requestTerminationImpl(PIDImpl pid);
|
||||||
static std::string terminationEventName(PIDImpl pid);
|
static std::string terminationEventName(PIDImpl pid);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -72,6 +72,8 @@ public:
|
|||||||
const EnvImpl& env);
|
const EnvImpl& env);
|
||||||
static void killImpl(ProcessHandleImpl& handle);
|
static void killImpl(ProcessHandleImpl& handle);
|
||||||
static void killImpl(PIDImpl pid);
|
static void killImpl(PIDImpl pid);
|
||||||
|
static bool isRunningImpl(const ProcessHandleImpl& handle);
|
||||||
|
static bool isRunningImpl(PIDImpl pid);
|
||||||
static void requestTerminationImpl(PIDImpl pid);
|
static void requestTerminationImpl(PIDImpl pid);
|
||||||
static std::string terminationEventName(PIDImpl pid);
|
static std::string terminationEventName(PIDImpl pid);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -191,6 +191,14 @@ void Process::kill(PID pid)
|
|||||||
killImpl(pid);
|
killImpl(pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Process::isRunning(const ProcessHandle& handle)
|
||||||
|
{
|
||||||
|
return isRunningImpl(*handle._pImpl);
|
||||||
|
}
|
||||||
|
bool Process::isRunning(PID pid)
|
||||||
|
{
|
||||||
|
return isRunningImpl(pid);
|
||||||
|
}
|
||||||
|
|
||||||
void Process::requestTermination(PID pid)
|
void Process::requestTermination(PID pid)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -220,7 +220,23 @@ void ProcessImpl::killImpl(PIDImpl pid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ProcessImpl::isRunningImpl(const ProcessHandleImpl& handle)
|
||||||
|
{
|
||||||
|
return isRunningImpl(handle.id());
|
||||||
|
}
|
||||||
|
bool ProcessImpl::isRunningImpl(PIDImpl pid)
|
||||||
|
{
|
||||||
|
if (kill(pid, 0) == 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ProcessImpl::requestTerminationImpl(PIDImpl pid)
|
void ProcessImpl::requestTerminationImpl(PIDImpl pid)
|
||||||
{
|
{
|
||||||
if (kill(pid, SIGINT) != 0)
|
if (kill(pid, SIGINT) != 0)
|
||||||
|
|||||||
@@ -139,6 +139,14 @@ void ProcessImpl::killImpl(PIDImpl pid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ProcessImpl::isRunningImpl(const ProcessHandleImpl& handle)
|
||||||
|
{
|
||||||
|
throw Poco::NotImplementedException("Process::is_running()");
|
||||||
|
}
|
||||||
|
bool ProcessImpl::isRunningImpl(PIDImpl pid)
|
||||||
|
{
|
||||||
|
throw Poco::NotImplementedException("Process::is_running()");
|
||||||
|
}
|
||||||
|
|
||||||
void ProcessImpl::requestTerminationImpl(PIDImpl pid)
|
void ProcessImpl::requestTerminationImpl(PIDImpl pid)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -80,6 +80,15 @@ void ProcessImpl::killImpl(PIDImpl pid)
|
|||||||
throw Poco::NotImplementedException("Process::kill()");
|
throw Poco::NotImplementedException("Process::kill()");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ProcessImpl::isRunningImpl(const ProcessHandleImpl& handle)
|
||||||
|
{
|
||||||
|
throw Poco::NotImplementedException("Process::is_running()");
|
||||||
|
}
|
||||||
|
bool ProcessImpl::isRunningImpl(PIDImpl pid)
|
||||||
|
{
|
||||||
|
throw Poco::NotImplementedException("Process::is_running()");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ProcessImpl::requestTerminationImpl(PIDImpl pid)
|
void ProcessImpl::requestTerminationImpl(PIDImpl pid)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -255,6 +255,27 @@ void ProcessImpl::killImpl(PIDImpl pid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ProcessImpl::isRunningImpl(const ProcessHandleImpl& handle)
|
||||||
|
{
|
||||||
|
BOOL fRC = true;
|
||||||
|
DWORD exit_code;
|
||||||
|
|
||||||
|
GetExitCodeProcess(handle.process(), &exit_code);
|
||||||
|
if (exit_code != STILL_ACTIVE) fRC = false;
|
||||||
|
|
||||||
|
return fRC;
|
||||||
|
}
|
||||||
|
bool ProcessImpl::isRunningImpl(PIDImpl pid)
|
||||||
|
{
|
||||||
|
HANDLE hProc = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
|
||||||
|
BOOL fRC = true;
|
||||||
|
DWORD exit_code;
|
||||||
|
|
||||||
|
GetExitCodeProcess(hProc, &exit_code);
|
||||||
|
if (exit_code != STILL_ACTIVE) fRC = false;
|
||||||
|
|
||||||
|
return fRC;
|
||||||
|
}
|
||||||
|
|
||||||
void ProcessImpl::requestTerminationImpl(PIDImpl pid)
|
void ProcessImpl::requestTerminationImpl(PIDImpl pid)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -261,6 +261,27 @@ void ProcessImpl::killImpl(PIDImpl pid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ProcessImpl::isRunningImpl(const ProcessHandleImpl& handle)
|
||||||
|
{
|
||||||
|
BOOL fRC = true;
|
||||||
|
DWORD exit_code;
|
||||||
|
|
||||||
|
GetExitCodeProcess(handle.process(), &exit_code);
|
||||||
|
if (exit_code != STILL_ACTIVE) fRC = false;
|
||||||
|
|
||||||
|
return fRC;
|
||||||
|
}
|
||||||
|
bool ProcessImpl::isRunningImpl(PIDImpl pid)
|
||||||
|
{
|
||||||
|
HANDLE hProc = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
|
||||||
|
BOOL fRC = true;
|
||||||
|
DWORD exit_code;
|
||||||
|
|
||||||
|
GetExitCodeProcess(hProc, &exit_code);
|
||||||
|
if (exit_code != STILL_ACTIVE) fRC = false;
|
||||||
|
|
||||||
|
return fRC;
|
||||||
|
}
|
||||||
|
|
||||||
void ProcessImpl::requestTerminationImpl(PIDImpl pid)
|
void ProcessImpl::requestTerminationImpl(PIDImpl pid)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -186,6 +186,28 @@ void ProcessImpl::killImpl(PIDImpl pid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ProcessImpl::isRunningImpl(const ProcessHandleImpl& handle)
|
||||||
|
{
|
||||||
|
BOOL fRC = true;
|
||||||
|
DWORD exit_code;
|
||||||
|
|
||||||
|
GetExitCodeProcess(handle.process(), &exit_code);
|
||||||
|
if (exit_code != STILL_ACTIVE) fRC = false;
|
||||||
|
|
||||||
|
return fRC;
|
||||||
|
}
|
||||||
|
bool ProcessImpl::isRunningImpl(PIDImpl pid)
|
||||||
|
{
|
||||||
|
HANDLE hProc = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
|
||||||
|
BOOL fRC = true;
|
||||||
|
DWORD exit_code;
|
||||||
|
|
||||||
|
GetExitCodeProcess(hProc, &exit_code);
|
||||||
|
if (exit_code != STILL_ACTIVE) fRC = false;
|
||||||
|
|
||||||
|
return fRC;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ProcessImpl::requestTerminationImpl(PIDImpl pid)
|
void ProcessImpl::requestTerminationImpl(PIDImpl pid)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -92,6 +92,35 @@ void ProcessTest::testLaunchRedirectIn()
|
|||||||
#endif // !defined(_WIN32_WCE)
|
#endif // !defined(_WIN32_WCE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProcessTest::testIsRunning()
|
||||||
|
{
|
||||||
|
std::string name("TestApp");
|
||||||
|
std::string cmd;
|
||||||
|
#if defined(_DEBUG)
|
||||||
|
name += "d";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(POCO_OS_FAMILY_UNIX)
|
||||||
|
cmd = "./";
|
||||||
|
cmd += name;
|
||||||
|
#else
|
||||||
|
cmd = name;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::vector<std::string> args;
|
||||||
|
args.push_back("-count");
|
||||||
|
Pipe inPipe;
|
||||||
|
ProcessHandle ph = Process::launch(cmd, args, &inPipe, 0, 0);
|
||||||
|
Process::PID id = ph.id();
|
||||||
|
assert (Process::isRunning(ph));
|
||||||
|
assert (Process::isRunning(id));
|
||||||
|
PipeOutputStream ostr(inPipe);
|
||||||
|
ostr << std::string(100, 'x');
|
||||||
|
ostr.close();
|
||||||
|
int rc = ph.wait();
|
||||||
|
assert (!Process::isRunning(ph));
|
||||||
|
assert (!Process::isRunning(id));
|
||||||
|
}
|
||||||
|
|
||||||
void ProcessTest::testLaunchRedirectOut()
|
void ProcessTest::testLaunchRedirectOut()
|
||||||
{
|
{
|
||||||
@@ -175,6 +204,7 @@ CppUnit::Test* ProcessTest::suite()
|
|||||||
CppUnit_addTest(pSuite, ProcessTest, testLaunchRedirectIn);
|
CppUnit_addTest(pSuite, ProcessTest, testLaunchRedirectIn);
|
||||||
CppUnit_addTest(pSuite, ProcessTest, testLaunchRedirectOut);
|
CppUnit_addTest(pSuite, ProcessTest, testLaunchRedirectOut);
|
||||||
CppUnit_addTest(pSuite, ProcessTest, testLaunchEnv);
|
CppUnit_addTest(pSuite, ProcessTest, testLaunchEnv);
|
||||||
|
CppUnit_addTest(pSuite, ProcessTest, testIsRunning);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ public:
|
|||||||
void testLaunchRedirectIn();
|
void testLaunchRedirectIn();
|
||||||
void testLaunchRedirectOut();
|
void testLaunchRedirectOut();
|
||||||
void testLaunchEnv();
|
void testLaunchEnv();
|
||||||
|
void testIsRunning();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
|||||||
Reference in New Issue
Block a user