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.
This commit is contained in:
Lukas Nykryn 2013-08-07 11:57:24 +02:00 committed by Jaromir Capik
parent f5d15f4718
commit d66ed3350e
3 changed files with 26 additions and 2 deletions

View File

@ -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

View File

@ -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},

View File

@ -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 .