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 <csmall@enc.com.au>

Ported-by: Jim Warner <james.warner@comcast.net>
From original:
commit 0ee090ae16
This commit is contained in:
Craig Small 2015-08-15 17:10:38 +10:00
parent 7b08ad19cc
commit 03b148d517
2 changed files with 24 additions and 1 deletions

View File

@ -313,6 +313,7 @@ setREL3(CMD,CMDLINE,ENVIRON)
return max_rightward-rightward; return max_rightward-rightward;
} }
static int pr_cgroup(char *restrict const outbuf,const proc_t *restrict const pp) { static int pr_cgroup(char *restrict const outbuf,const proc_t *restrict const pp) {
int rightward = max_rightward; int rightward = max_rightward;
setREL1(CGROUP) setREL1(CGROUP)
@ -320,6 +321,23 @@ setREL1(CGROUP)
return max_rightward-rightward; 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 */ /* Non-standard, from SunOS 5 */
static int pr_fname(char *restrict const outbuf, const proc_t *restrict const pp){ static int pr_fname(char *restrict const outbuf, const proc_t *restrict const pp){
char *endp = outbuf; 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}, {"bsdtime", "TIME", pr_bsdtime, PROCPS_PIDS_TICS_ALL, 6, LNX, ET|RIGHT},
{"c", "C", pr_c, PROCPS_PIDS_extra, 2, SUN, 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*/ {"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}, {"cgroup", "CGROUP", pr_cgroup, PROCPS_PIDS_CGROUP, 27, LNX, PO|UNLIMITED},
{"class", "CLS", pr_class, PROCPS_PIDS_SCHED_CLASS, 3, XXX, TO|LEFT}, {"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*/ {"cls", "CLS", pr_class, PROCPS_PIDS_SCHED_CLASS, 3, HPU, TO|RIGHT}, /*says HPUX or RT*/

View File

@ -4,7 +4,7 @@
.\" Quick hack conversion by Albert Cahalan, 1998. .\" Quick hack conversion by Albert Cahalan, 1998.
.\" Licensed under version 2 of the Gnu General Public License. .\" 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: .\" To render this page:
.\" groff -t -b -man -X -P-resolution -P100 -Tps ps.1 & .\" groff -t -b -man -X -P-resolution -P100 -Tps ps.1 &
@ -1080,6 +1080,10 @@ format is displayed. (alias
.BR sig_catch , \ sigcatch ). .BR sig_catch , \ sigcatch ).
T} T}
cgname CGNAME T{
display name of control groups to which the process belongs.
T}
cgroup CGROUP T{ cgroup CGROUP T{
display control groups to which the process belongs. display control groups to which the process belongs.
T} T}