process-util: shortcut get_process_state() for our own process

This commit is contained in:
Lennart Poettering 2019-11-25 14:59:01 +01:00
parent cde93ba2a5
commit 5c7b99745a
1 changed files with 5 additions and 1 deletions

View File

@ -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);