diff --git a/base/process.cpp b/base/process.cpp index 887f2d475..61650cb38 100644 --- a/base/process.cpp +++ b/base/process.cpp @@ -1,5 +1,5 @@ // LAF Base Library -// Copyright (c) 2021 Igara Studio S.A. +// Copyright (c) 2021-2023 Igara Studio S.A. // Copyright (c) 2015-2016 David Capello // // This file is released under the terms of the MIT license. @@ -11,9 +11,12 @@ #include "base/process.h" +#include + #if LAF_WINDOWS #include #else + #include #include #include #include @@ -28,7 +31,7 @@ pid get_current_process_id() return (pid)GetCurrentProcessId(); } -bool is_process_running(pid pid) +bool is_process_running(pid pid, const char* pname) { bool running = false; @@ -44,14 +47,29 @@ bool is_process_running(pid pid) return running; } -#else // !LAF_WINDOWS +#elif LAF_MACOS + +pid get_current_process_id() +{ + return (pid)getpid(); +} + +bool is_process_running(pid pid, const char* pname) +{ + struct proc_bsdinfo process; + proc_pidinfo(pid, PROC_PIDTBSDINFO, 0, + &process, PROC_PIDTBSDINFO_SIZE); + return (strcmp(pname, process.pbi_name) == 0); +} + +#elif LAF_LINUX pid get_current_process_id() { return (pid)getpid(); } -bool is_process_running(pid pid) +bool is_process_running(pid pid, const char* pname) { return (kill(pid, 0) == 0); } diff --git a/base/process.h b/base/process.h index 445b87cd6..8085ffe20 100644 --- a/base/process.h +++ b/base/process.h @@ -1,4 +1,5 @@ // LAF Base Library +// Copyright (c) 2023 Igara Studio S.A. // Copyright (c) 2015-2016 David Capello // // This file is released under the terms of the MIT license. @@ -16,7 +17,7 @@ namespace base { pid get_current_process_id(); - bool is_process_running(pid pid); + bool is_process_running(pid pid, const char* pname); } // namespace base