diff -up procps-3.2.7/ps/output.c.pom procps-3.2.7/ps/output.c --- procps-3.2.7/ps/output.c.pom 2009-02-15 13:16:27.000000000 +0100 +++ procps-3.2.7/ps/output.c 2009-02-15 14:02:34.000000000 +0100 @@ -1097,6 +1097,40 @@ static int pr_sgi_p(char *restrict const return snprintf(outbuf, COLWID, "*"); } +static int pr_cgroup(char *restrict const outbuf, const proc_t *restrict const pp){ + char filename[48]; + FILE *fd; + int counter = 0; + int c; + int is_cgroup = 0; + + outbuf[0]='\0'; + snprintf(filename, sizeof filename, "/proc/%d/cgroup", pp->tgid); + fd = fopen(filename, "r"); + if (likely(fd == NULL)) goto fail; + while (( (c = fgetc(fd)) != EOF) && (counter<665)) { + if (is_cgroup == 0) { + if (c == ':') { + is_cgroup = 1; + if (counter>0) + outbuf[counter++]=';'; + } + }else + if ((c == '\n') || (c == '\0')) + is_cgroup = 0; + else + outbuf[counter++]=c; + } + outbuf[counter]='\0'; + close(fd); + if (counter>0) + return counter; +fail: + outbuf[0] = '-'; + outbuf[1] = '\0'; + return 1; +} + #ifdef STATICLIB /****************** FLASK & seLinux security stuff **********************/ // move the bulk of this to libproc sometime @@ -1291,6 +1325,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*/ +{"cgroup", "CGROUP", pr_cgroup, sr_nop, 35, 0, LNX, PO|LEFT}, /* cgroups*/ {"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*/ {"cmaj_flt", "-", pr_nop, sr_cmaj_flt, 1, 0, LNX, AN|RIGHT}, diff -up procps-3.2.7/ps/ps.1.pom procps-3.2.7/ps/ps.1 --- procps-3.2.7/ps/ps.1.pom 2009-02-15 13:16:27.000000000 +0100 +++ procps-3.2.7/ps/ps.1 2009-02-15 14:00:33.000000000 +0100 @@ -908,6 +908,10 @@ width of the field, a 32 or 64 bits mask displayed. (alias\ \fBsig_catch\fR,\ \fBsigcatch\fR). T} +cgroup CGROUP T{ +display control groups to which the process belonges. +t} + class CLS T{ scheduling class of the process. (alias\ \fBpolicy\fR,\ \fBcls\fR). Field's possible values are: