]> granicus.if.org Git - procps-ng/commitdiff
ps: display control group name
authorCraig Small <csmall@enc.com.au>
Sat, 15 Aug 2015 07:10:38 +0000 (17:10 +1000)
committerCraig Small <csmall@enc.com.au>
Wed, 14 Oct 2015 10:34:37 +0000 (21:34 +1100)
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 <csmall@enc.com.au>
Ported-by: Jim Warner <james.warner@comcast.net>
From original:
commit 0ee090ae16a3a98ba64a1bb8108597328a4c05b0

ps/output.c
ps/ps.1

index 866f135f299b718ed98f43f3e1ea3cbcd79c3970..bff7f5cedd828a0c4e6b6ebe852c0a10fa51e2b9 100644 (file)
@@ -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 bce55bd9f4d812205a60f523d734775e6e2a3bd7..ee9c38f0b3c262487fbdbb3e7827b53381fa8d3c 100644 (file)
--- 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}