Commit 0ee090ae authored by Craig Small's avatar Craig Small

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's avatarCraig Small <csmall@enc.com.au>
parent 4bd0e539
procps-ng-NEXT
----------------
* ps: sort by cgroup Debian #692279
* ps: display control group name with -o cgname
procps-ng-3.3.11
----------------
......
......@@ -98,13 +98,29 @@ static int sr_nop(const proc_t* a, const proc_t* b){
static int sr_cgroup(const proc_t* a, const proc_t* b)
{
int i;
int cmpval;
for (i=0; a->cgroup[i] != NULL && b->cgroup[i] != NULL; i++) {
if ((cmpval = strcmp(a->cgroup[i], b->cgroup[i])) != 0)
return cmpval;
}
return 0;
/* This is a "vector" of one */
if (*a->cgroup == NULL || *b->cgroup == NULL)
return 0;
return strcmp(*a->cgroup, *b->cgroup);
}
static int sr_cgname(const proc_t* a, const proc_t* b)
{
char *aname, *bname;
/* This is a "vector" of one */
if (*a->cgroup == NULL || *b->cgroup == NULL)
return 0;
aname = strstr(*a->cgroup, ":name=");
bname = strstr(*b->cgroup, ":name=");
/* check for missing names, they win */
if (aname == NULL || aname[6] == '\0') {
if (bname == NULL || bname[6] == '\0')
return 0;
return -1;
} else if (bname == NULL || bname[6] == '\0')
return 1;
return strcmp(aname+6,bname+6);
}
......@@ -455,6 +471,22 @@ static int pr_cgroup(char *restrict const outbuf,const proc_t *restrict const pp
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;
if ((name = strstr(*pp->cgroup, ":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;
......@@ -1451,6 +1483,7 @@ static const format_struct format_array[] = {
{"bsdtime", "TIME", pr_bsdtime, sr_nop, 6, 0, LNX, ET|RIGHT},
{"c", "C", pr_c, sr_pcpu, 2, 0, SUN, ET|RIGHT},
{"caught", "CAUGHT", pr_sigcatch, sr_nop, 9, 0, BSD, TO|SIGNAL}, /*sigcatch*/
{"cgname", "CGNAME", pr_cgname, sr_cgname, 27,CGRP, LNX, PO|UNLIMITED},
{"cgroup", "CGROUP", pr_cgroup, sr_cgroup, 27,CGRP, LNX, PO|UNLIMITED},
{"class", "CLS", pr_class, sr_sched, 3, 0, XXX, TO|LEFT},
{"cls", "CLS", pr_class, sr_sched, 3, 0, HPU, TO|RIGHT}, /*says HPUX or RT*/
......
......@@ -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}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment