diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-10-27 14:02:45 +0100 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2017-04-26 12:58:55 +0200 |
commit | 4060a1603b2e82e6086a13456139f306736571e8 (patch) | |
tree | 304e55374d6ccd13e578cf99a27376dbb510e240 | |
parent | abc8019b64273b4f15dfe082a58b9f3f42823904 (diff) |
process-util: make some minor corrections to PID live detection
-rw-r--r-- | src/basic/process-util.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 8a1f54db8..5825944c9 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -556,9 +556,12 @@ int getenv_for_pid(pid_t pid, const char *field, char **_value) { bool pid_is_unwaited(pid_t pid) { /* Checks whether a PID is still valid at all, including a zombie */ - if (pid <= 0) + if (pid < 0) return false; + if (pid <= 1) /* If we or PID 1 would be dead and have been waited for, this code would not be running */ + return true; + if (kill(pid, 0) >= 0) return true; @@ -570,9 +573,12 @@ bool pid_is_alive(pid_t pid) { /* Checks whether a PID is still valid and not a zombie */ - if (pid <= 0) + if (pid < 0) return false; + if (pid <= 1) /* If we or PID 1 would be a zombie, this code would not be running */ + return true; + r = get_process_state(pid); if (r == -ESRCH || r == 'Z') return false; |