diff options
author | Lennart Poettering <lennart@poettering.net> | 2012-01-22 18:18:51 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2012-01-22 18:22:26 +0100 |
commit | 1e5678d023ab57807d3de08e10304e36bf9a1950 (patch) | |
tree | 6403512f2063b03a5b433bd45a7d7462b05de983 /src/util.c | |
parent | ce3fd7e72a1b101002617bd410031e65d290f56f (diff) |
cgls: don't show kernel threads by default
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c index de5feeb8d0..ef6eea4b9f 100644 --- a/src/util.c +++ b/src/util.c @@ -1100,6 +1100,37 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char * return 0; } +int is_kernel_thread(pid_t pid) { + char *p; + size_t count; + char c; + bool eof; + FILE *f; + + if (pid == 0) + return 0; + + if (asprintf(&p, "/proc/%lu/cmdline", (unsigned long) pid) < 0) + return -ENOMEM; + + f = fopen(p, "re"); + free(p); + + if (!f) + return -errno; + + count = fread(&c, 1, 1, f); + eof = feof(f); + fclose(f); + + /* Kernel threads have an empty cmdline */ + + if (count <= 0) + return eof ? 1 : -errno; + + return 0; +} + int get_process_exe(pid_t pid, char **name) { int r; |