Skip to content

Commit

Permalink
Fix 'is_process_running' for Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
martincapello committed Jan 16, 2024
1 parent bb1d53e commit 59773cd
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions base/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
#include <string.h>
#endif

#if LAF_LINUX
#include "base/fs.h"
#include <stdlib.h>
#endif
namespace base {

#if LAF_WINDOWS
Expand Down Expand Up @@ -107,12 +111,22 @@ pid get_current_process_id()

bool is_process_running(pid pid, const char* pname)
{
return (kill(pid, 0) == 0);
char path[128];
memset(path, 0, 128);
sprintf(path, "/proc/%d/exe", pid);
char* exepath = realpath(path, nullptr);
if (!exepath)
return false;

auto exename = base::get_file_name(exepath);
free(exepath);

return exename == std::string(pname);
}

bool is_process_running(pid pid)
{
return is_process_running(pid, "");
return (kill(pid, 0) == 0);
}

#endif
Expand Down

0 comments on commit 59773cd

Please sign in to comment.