diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 003aecbc49..9b6c4c31f7 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -52,13 +52,17 @@ #define COMM_MAX_LEN 128 static int get_process_state(pid_t pid) { + _cleanup_free_ char *line = NULL; const char *p; char state; int r; - _cleanup_free_ char *line = NULL; assert(pid >= 0); + /* Shortcut: if we are enquired about our own state, we are obviously running */ + if (pid == 0 || pid == getpid_cached()) + return (unsigned char) 'R'; + p = procfs_file_alloca(pid, "stat"); r = read_one_line_file(p, &line);