From 03b148d5178b6ab8a11f7171cd07ceccd449ad8c Mon Sep 17 00:00:00 2001 From: Craig Small Date: Sat, 15 Aug 2015 17:10:38 +1000 Subject: [PATCH] ps: display control group name The cgroup field while shown as a vector is a concatenated string, so alot of the complexity of sorting and displaying has gone. This change simplifies the cgroup sorting and adds display and sorting for the name attribute of the cgroup, if found. Signed-off-by: Craig Small Ported-by: Jim Warner From original: commit 0ee090ae16a3a98ba64a1bb8108597328a4c05b0 --- ps/output.c | 19 +++++++++++++++++++ ps/ps.1 | 6 +++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/ps/output.c b/ps/output.c index 866f135f..bff7f5ce 100644 --- a/ps/output.c +++ b/ps/output.c @@ -313,6 +313,7 @@ setREL3(CMD,CMDLINE,ENVIRON) return max_rightward-rightward; } + static int pr_cgroup(char *restrict const outbuf,const proc_t *restrict const pp) { int rightward = max_rightward; setREL1(CGROUP) @@ -320,6 +321,23 @@ setREL1(CGROUP) return max_rightward-rightward; } +static int pr_cgname(char *restrict const outbuf,const proc_t *restrict const pp) { + int rightward = max_rightward; + int i; + char *name; +setREL1(CGROUP) + + if ((name = strstr(rSv(CGROUP, str, pp), ":name=")) != NULL) { + name += 6; + if (name != '\0') { + escape_str(outbuf, name, OUTBUF_SIZE, &rightward); + return max_rightward - rightward; + } + } + /* fallback: use full cgroup for name */ + return pr_cgroup(outbuf, pp); +} + /* Non-standard, from SunOS 5 */ static int pr_fname(char *restrict const outbuf, const proc_t *restrict const pp){ char *endp = outbuf; @@ -1390,6 +1408,7 @@ static const format_struct format_array[] = { /* {"bsdtime", "TIME", pr_bsdtime, PROCPS_PIDS_TICS_ALL, 6, LNX, ET|RIGHT}, {"c", "C", pr_c, PROCPS_PIDS_extra, 2, SUN, ET|RIGHT}, {"caught", "CAUGHT", pr_sigcatch, PROCPS_PIDS_SIGCATCH, 9, BSD, TO|SIGNAL}, /*sigcatch*/ +{"cgname", "CGNAME", pr_cgname, PROCPS_PIDS_CGROUP, 27, LNX, PO|UNLIMITED}, {"cgroup", "CGROUP", pr_cgroup, PROCPS_PIDS_CGROUP, 27, LNX, PO|UNLIMITED}, {"class", "CLS", pr_class, PROCPS_PIDS_SCHED_CLASS, 3, XXX, TO|LEFT}, {"cls", "CLS", pr_class, PROCPS_PIDS_SCHED_CLASS, 3, HPU, TO|RIGHT}, /*says HPUX or RT*/ diff --git a/ps/ps.1 b/ps/ps.1 index bce55bd9..ee9c38f0 100644 --- a/ps/ps.1 +++ b/ps/ps.1 @@ -4,7 +4,7 @@ .\" Quick hack conversion by Albert Cahalan, 1998. .\" Licensed under version 2 of the Gnu General Public License. .\" -.TH PS 1 "June 2015" "procps-ng" "User Commands" +.TH PS 1 "August 2015" "procps-ng" "User Commands" .\" .\" To render this page: .\" groff -t -b -man -X -P-resolution -P100 -Tps ps.1 & @@ -1080,6 +1080,10 @@ format is displayed. (alias .BR sig_catch , \ sigcatch ). T} +cgname CGNAME T{ +display name of control groups to which the process belongs. +T} + cgroup CGROUP T{ display control groups to which the process belongs. T}