diff options
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/util.c | 25 | ||||
-rw-r--r-- | src/shared/util.h | 1 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c index 3482b9b743..b1a9db1d46 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -513,6 +513,31 @@ char *truncate_nl(char *s) { return s; } +int get_process_state(pid_t pid) { + const char *p; + char state; + int r; + _cleanup_free_ char *line = NULL; + + assert(pid >= 0); + + p = procfs_file_alloca(pid, "stat"); + r = read_one_line_file(p, &line); + if (r < 0) + return r; + + p = strrchr(line, ')'); + if (!p) + return -EIO; + + p++; + + if (sscanf(p, " %c", &state) != 1) + return -EIO; + + return (unsigned char) state; +} + int get_process_comm(pid_t pid, char **name) { const char *p; int r; diff --git a/src/shared/util.h b/src/shared/util.h index 9aea3a4e50..8dede1f7ff 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -238,6 +238,7 @@ char *file_in_same_dir(const char *path, const char *filename); int rmdir_parents(const char *path, const char *stop); +char get_process_state(pid_t pid); int get_process_comm(pid_t pid, char **name); int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char **line); int get_process_exe(pid_t pid, char **name); |