summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c25
1 files changed, 25 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;