Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions Source/Process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -573,53 +573,53 @@ 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);

// 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
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 11 additions & 6 deletions Test/Process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand Down