From f3bfa77eed05b69f00dec5aae9d06cf356b0d67a Mon Sep 17 00:00:00 2001 From: dkrutsko Date: Sun, 5 Mar 2017 16:03:45 -0500 Subject: [PATCH 1/2] Initial implementation --- Source/Process.cc | 26 +++++++++++++------------- Source/Process.h | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Source/Process.cc b/Source/Process.cc index d2cd38c..330fe4f 100644 --- a/Source/Process.cc +++ b/Source/Process.cc @@ -573,23 +573,23 @@ string Process::GetPath (void) const //////////////////////////////////////////////////////////////////////////////// -void Process::Exit (void) +bool Process::Exit (void) { - // Check process validity - if (!IsValid()) return; - #ifdef ROBOT_OS_LINUX - kill (mData->ProcID, SIGTERM); + return kill (mData->ProcID, SIGTERM) == 0; #endif #ifdef ROBOT_OS_MAC - kill (mData->ProcID, SIGTERM); + return kill (mData->ProcID, SIGTERM) == 0; #endif #ifdef ROBOT_OS_WIN + // Check the process validity + if (!IsValid()) return false; + // Get every process window auto list = Window::GetList (nullptr, mData->ProcID); @@ -597,29 +597,29 @@ void Process::Exit (void) // Close every open window in the process for (auto& window : list) window.Close(); + // True if not empty + return !list.empty(); + #endif } //////////////////////////////////////////////////////////////////////////////// -void Process::Kill (void) +bool Process::Kill (void) { - // Check process validity - if (!IsValid()) return; - #ifdef ROBOT_OS_LINUX - kill (mData->ProcID, SIGKILL); + return kill (mData->ProcID, SIGKILL) == 0; #endif #ifdef ROBOT_OS_MAC - kill (mData->ProcID, SIGKILL); + return kill (mData->ProcID, SIGKILL) == 0; #endif #ifdef ROBOT_OS_WIN - TerminateProcess (mData->Handle, -1); + return TerminateProcess (mData->Handle, -1) != FALSE; #endif } diff --git a/Source/Process.h b/Source/Process.h index fc139eb..7e8c69e 100644 --- a/Source/Process.h +++ b/Source/Process.h @@ -74,8 +74,8 @@ class ROBOT_EXPORT Process std::string GetName (void) const; std::string GetPath (void) const; - void Exit (void); - void Kill (void); + bool Exit (void); + bool Kill (void); bool HasExited (void) const; ModuleList GetModules (const char* name = nullptr) const; From 00a7bbeabbb28adf49bb32f688e0e89ec23de113 Mon Sep 17 00:00:00 2001 From: dkrutsko Date: Sun, 5 Mar 2017 16:03:55 -0500 Subject: [PATCH 2/2] Updated test cases --- Test/Process.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Test/Process.cc b/Test/Process.cc index 05cc4dc..83036d2 100644 --- a/Test/Process.cc +++ b/Test/Process.cc @@ -50,10 +50,15 @@ static bool TestInvalid (void) Process p3; VERIFY (!p3.Open (-1)); Process p4 (8888); - VERIFY (!p1.IsValid()); VERIFY (!p1.Is64Bit()); VERIFY (p1.HasExited()); - VERIFY (!p2.IsValid()); VERIFY (!p2.Is64Bit()); VERIFY (p2.HasExited()); - VERIFY (!p3.IsValid()); VERIFY (!p3.Is64Bit()); VERIFY (p3.HasExited()); - VERIFY (!p4.IsValid()); VERIFY (!p4.Is64Bit()); VERIFY (p4.HasExited()); + VERIFY (!p1.IsValid()); VERIFY (!p1.Is64Bit()); + VERIFY (!p2.IsValid()); VERIFY (!p2.Is64Bit()); + VERIFY (!p3.IsValid()); VERIFY (!p3.Is64Bit()); + VERIFY (!p4.IsValid()); VERIFY (!p4.Is64Bit()); + + VERIFY (!p1.Exit()); VERIFY (!p1.Kill()); VERIFY (p1.HasExited()); + VERIFY (!p2.Exit()); VERIFY (!p2.Kill()); VERIFY (p2.HasExited()); + VERIFY (!p3.Exit()); VERIFY (!p3.Kill()); VERIFY (p3.HasExited()); + VERIFY (!p4.Exit()); VERIFY (!p4.Kill()); VERIFY (p4.HasExited()); VERIFY (p1.GetPID() == 0); VERIFY (p1.GetHandle() == 0); VERIFY (p2.GetPID() == 0); VERIFY (p2.GetHandle() == 0); @@ -162,8 +167,8 @@ static bool TestSelect (void) cout << "Type something in both apps then press enter"; getchar(); - p1.Exit(); - p2.Kill(); + VERIFY (p1.Exit()); + VERIFY (p2.Kill()); cout << "Close both applications and then press enter"; getchar();