summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Nykryn <lnykryn@redhat.com>2013-08-07 11:57:24 +0200
committerJaromir Capik <jcapik@redhat.com>2013-10-16 15:18:08 +0200
commitd66ed3350e939c6649c42e0a880b5870b33d66b8 (patch)
tree862b12e3cc9717de6ece98186c0762574189ac67
parentf5d15f471890ed8ae1006b0007ff1bc7a5b9476d (diff)
downloadprocps-ng-d66ed3350e939c6649c42e0a880b5870b33d66b8.tar.gz
ps: possibility to display slice unit for a process
Library systemd-login offers possibility to display name of a systemd slice unit for specific pid. This patch adds output option "slice" which will show name of systemd slice unit. To maintain compatibility with non-systemd systems, procps must be configured with --with-systemd option to enable this option.
-rw-r--r--configure.ac4
-rw-r--r--ps/output.c20
-rw-r--r--ps/ps.14
3 files changed, 26 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac
index 20bc3ce..f08867c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -154,8 +154,8 @@ AC_ARG_WITH([systemd],
[], [with_systemd=no]
)
if test "x$with_systemd" != xno; then
- PKG_CHECK_MODULES([SYSTEMD], [libsystemd-login >= 202], [], [
- AC_CHECK_LIB(systemd-login, sd_pid_get_machine_name, [have_systemd=yes], [have_systemd=no])
+ PKG_CHECK_MODULES([SYSTEMD], [libsystemd-login >= 206], [], [
+ AC_CHECK_LIB(systemd-login, sd_pid_get_slice, [have_systemd=yes], [have_systemd=no])
if test "x$have_systemd" = xno; then
AC_MSG_ERROR([systemd support missing/incomplete])
fi
diff --git a/ps/output.c b/ps/output.c
index 2e9056e..9be334e 100644
--- a/ps/output.c
+++ b/ps/output.c
@@ -1292,6 +1292,23 @@ fail:
return 1;
}
+static int pr_sd_slice(char *restrict const outbuf, const proc_t *restrict const pp){
+ int r;
+ size_t len;
+ char *slice;
+
+ r = sd_pid_get_slice(pp->tgid, &slice);
+ if(r<0) goto fail;
+ len = snprintf(outbuf, COLWID, "%s", slice);
+ free(slice);
+ return len;
+
+fail:
+ outbuf[0] = '-';
+ outbuf[1] = '\0';
+ return 1;
+}
+
#endif
/************************ Linux namespaces ******************************/
@@ -1675,6 +1692,9 @@ static const format_struct format_array[] = {
{"sigmask", "BLOCKED", pr_sigmask, sr_nop, 9, 0, XXX, TO|SIGNAL}, /*blocked*/
{"size", "SIZE", pr_swapable, sr_swapable, 5, 0, SCO, PO|RIGHT},
{"sl", "SL", pr_nop, sr_nop, 3, 0, XXX, AN|RIGHT},
+#ifdef WITH_SYSTEMD
+{"slice", "SLICE", pr_sd_slice, sr_nop, 31, 0, LNX, ET|LEFT},
+#endif
{"spid", "SPID", pr_tasks, sr_tasks, 5, 0, SGI, TO|PIDMAX|RIGHT},
{"stackp", "STACKP", pr_stackp, sr_start_stack, 8, 0, LNX, PO|RIGHT}, /*start_stack*/
{"start", "STARTED", pr_start, sr_nop, 8, 0, XXX, ET|RIGHT},
diff --git a/ps/ps.1 b/ps/ps.1
index 80e5ce8..cdb7536 100644
--- a/ps/ps.1
+++ b/ps/ps.1
@@ -1582,6 +1582,10 @@ to dirty all writable pages and then be swapped out. This number is very
rough!
T}
+slice SLICE T{
+displays slice unit which a process belongs to.
+T}
+
spid SPID T{
see
.BR lwp .