diff options
author | dec05eba <dec05eba@protonmail.com> | 2025-01-04 02:30:14 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2025-01-04 02:30:14 +0100 |
commit | f4dc07729938b53f94cc7410b2f1c6f5741636fb (patch) | |
tree | 0f42065d83a993f825a475015932ecdd497d8304 /src/Process.cpp | |
parent | 36c7bbfda38d93c01b05d453276295ead289ea0e (diff) |
pidof ignore self
Diffstat (limited to 'src/Process.cpp')
-rw-r--r-- | src/Process.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/Process.cpp b/src/Process.cpp index c5692f5..c5fcf0f 100644 --- a/src/Process.cpp +++ b/src/Process.cpp @@ -206,7 +206,7 @@ namespace gsr { return false; } - pid_t pidof(const char *process_name) { + pid_t pidof(const char *process_name, pid_t ignore_pid) { pid_t result = -1; DIR *dir = opendir("/proc"); if(!dir) @@ -222,8 +222,11 @@ namespace gsr { snprintf(cmdline_filepath, sizeof(cmdline_filepath), "/proc/%s/cmdline", entry->d_name); if(read_cmdline_arg0(cmdline_filepath, arg0, sizeof(arg0)) && strcmp(process_name, arg0) == 0) { - result = atoi(entry->d_name); - break; + const pid_t pid = atoi(entry->d_name); + if(pid != ignore_pid) { + result = pid; + break; + } } } |