mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-14 23:07:56 +02:00
add is_running support
This commit is contained in:
@@ -217,6 +217,15 @@ public:
|
||||
/// Waits for the process specified by handle to terminate
|
||||
/// 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);
|
||||
/// Kills the process specified by handle.
|
||||
///
|
||||
|
@@ -66,6 +66,8 @@ public:
|
||||
const EnvImpl& env);
|
||||
static void killImpl(ProcessHandleImpl& handle);
|
||||
static void killImpl(PIDImpl pid);
|
||||
static bool isRunningImpl(const ProcessHandleImpl& handle);
|
||||
static bool isRunningImpl(PIDImpl pid);
|
||||
static void requestTerminationImpl(PIDImpl pid);
|
||||
|
||||
private:
|
||||
|
@@ -67,6 +67,8 @@ public:
|
||||
static int waitImpl(PIDImpl pid);
|
||||
static void killImpl(ProcessHandleImpl& handle);
|
||||
static void killImpl(PIDImpl pid);
|
||||
static bool isRunningImpl(const ProcessHandleImpl& handle);
|
||||
static bool isRunningImpl(PIDImpl pid);
|
||||
static void requestTerminationImpl(PIDImpl pid);
|
||||
};
|
||||
|
||||
|
@@ -68,6 +68,8 @@ public:
|
||||
const EnvImpl& env);
|
||||
static void killImpl(ProcessHandleImpl& handle);
|
||||
static void killImpl(PIDImpl pid);
|
||||
static bool isRunningImpl(const ProcessHandleImpl& handle);
|
||||
static bool isRunningImpl(PIDImpl pid);
|
||||
static void requestTerminationImpl(PIDImpl pid);
|
||||
};
|
||||
|
||||
|
@@ -72,6 +72,8 @@ public:
|
||||
const EnvImpl& env);
|
||||
static void killImpl(ProcessHandleImpl& handle);
|
||||
static void killImpl(PIDImpl pid);
|
||||
static bool isRunningImpl(const ProcessHandleImpl& handle);
|
||||
static bool isRunningImpl(PIDImpl pid);
|
||||
static void requestTerminationImpl(PIDImpl pid);
|
||||
static std::string terminationEventName(PIDImpl pid);
|
||||
};
|
||||
|
@@ -72,6 +72,8 @@ public:
|
||||
const EnvImpl& env);
|
||||
static void killImpl(ProcessHandleImpl& handle);
|
||||
static void killImpl(PIDImpl pid);
|
||||
static bool isRunningImpl(const ProcessHandleImpl& handle);
|
||||
static bool isRunningImpl(PIDImpl pid);
|
||||
static void requestTerminationImpl(PIDImpl pid);
|
||||
static std::string terminationEventName(PIDImpl pid);
|
||||
};
|
||||
|
@@ -72,6 +72,8 @@ public:
|
||||
const EnvImpl& env);
|
||||
static void killImpl(ProcessHandleImpl& handle);
|
||||
static void killImpl(PIDImpl pid);
|
||||
static bool isRunningImpl(const ProcessHandleImpl& handle);
|
||||
static bool isRunningImpl(PIDImpl pid);
|
||||
static void requestTerminationImpl(PIDImpl pid);
|
||||
static std::string terminationEventName(PIDImpl pid);
|
||||
};
|
||||
|
@@ -191,6 +191,14 @@ void Process::kill(PID 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)
|
||||
{
|
||||
|
@@ -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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
@@ -80,6 +80,15 @@ void ProcessImpl::killImpl(PIDImpl pid)
|
||||
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)
|
||||
{
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user