From 028e445dca4c18e28a97663b432cdade03edeccb Mon Sep 17 00:00:00 2001 From: martincapello Date: Tue, 16 Jan 2024 15:59:40 -0300 Subject: [PATCH] Fix 'is_process_running' for Linux --- base/process.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/base/process.cpp b/base/process.cpp index ab610c2a4..5a79366a0 100644 --- a/base/process.cpp +++ b/base/process.cpp @@ -26,6 +26,11 @@ #include #endif +#if LAF_LINUX + #include "base/fs.h" + #include + #include +#endif namespace base { #if LAF_WINDOWS @@ -107,12 +112,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