summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-04-20 15:28:28 +0200
committerSven Eden <yamakuzure@gmx.net>2017-06-16 10:12:58 +0200
commit09afb73b0829acd3fd965eb55f85c5614b45b023 (patch)
tree9b0a03209832f23c94a4d6cd0e43ae55b97c900c /src/basic
parent35f78d53d1944f36139028820762ae8fa9884bdd (diff)
core,systemctl: add bus API to retrieve processes of a unit
This adds a new GetProcesses() bus call to the Unit object which returns an array consisting of all PIDs, their process names, as well as their full cgroup paths. This is then used by "systemctl status" to show the per-unit process tree. This has the benefit that the client-side no longer needs to access the cgroupfs directly to show the process tree of a unit. Instead, it now uses this new API, which means it also works if -H or -M are used correctly, as the information from the specific host is used, and not the one from the local system. Fixes: #2945
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/process-util.c12
-rw-r--r--src/basic/process-util.h2
2 files changed, 14 insertions, 0 deletions
diff --git a/src/basic/process-util.c b/src/basic/process-util.c
index ed850824f..d146638b8 100644
--- a/src/basic/process-util.c
+++ b/src/basic/process-util.c
@@ -742,6 +742,18 @@ void valgrind_summary_hack(void) {
#endif
}
+int pid_compare_func(const void *a, const void *b) {
+ const pid_t *p = a, *q = b;
+
+ /* Suitable for usage in qsort() */
+
+ if (*p < *q)
+ return -1;
+ if (*p > *q)
+ return 1;
+ return 0;
+}
+
static const char *const ioprio_class_table[] = {
[IOPRIO_CLASS_NONE] = "none",
[IOPRIO_CLASS_RT] = "realtime",
diff --git a/src/basic/process-util.h b/src/basic/process-util.h
index d9c62aa9c..66b6cd13a 100644
--- a/src/basic/process-util.h
+++ b/src/basic/process-util.h
@@ -113,3 +113,5 @@ int sched_policy_from_string(const char *s);
#define PID_TO_PTR(p) ((void*) ((uintptr_t) p))
void valgrind_summary_hack(void);
+
+int pid_compare_func(const void *a, const void *b);