--- src/ps/output.c.orig	2010-09-23 13:04:13.000000000 +0900
+++ src/ps/output.c	2010-09-23 13:09:11.000000000 +0900
@@ -1099,6 +1099,46 @@
   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, last_begin = 0, slash = 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;
+        slash = 0;
+        if (counter>0)
+          outbuf[counter++]=';';
+      }
+    }else
+      if ((c == '\n') || (c == '\0')){
+        if (slash)  /* if the last char was a / this process is in the root cgroup which we should suppress */
+            counter = last_begin;
+      else
+            last_begin = counter;
+        is_cgroup = 0;
+      } else {
+        slash = c == '/';
+        outbuf[counter++]=c;
+  }
+  }
+  outbuf[counter]='\0';
+  close(fd);
+  if (counter>0) 
+    return counter;
+fail:
+  outbuf[0] = '-';
+  outbuf[1] = '\0';
+  return 1;
+}
 
 /****************** FLASK & seLinux security stuff **********************/
 // move the bulk of this to libproc sometime
@@ -1293,6 +1333,7 @@
 {"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},
