From 5c7b99745a7375ebae125f27c2872919089c0d5c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 25 Nov 2019 14:59:01 +0100 Subject: [PATCH] process-util: shortcut get_process_state() for our own process --- src/basic/process-util.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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);