procps-3.2.7-ps-cgroup.patch 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. diff -up procps-3.2.7/ps/output.c.pom procps-3.2.7/ps/output.c
  2. --- procps-3.2.7/ps/output.c.pom 2009-02-15 13:16:27.000000000 +0100
  3. +++ procps-3.2.7/ps/output.c 2009-02-15 14:02:34.000000000 +0100
  4. @@ -1097,6 +1097,40 @@ static int pr_sgi_p(char *restrict const
  5. return snprintf(outbuf, COLWID, "*");
  6. }
  7. +static int pr_cgroup(char *restrict const outbuf, const proc_t *restrict const pp){
  8. + char filename[48];
  9. + FILE *fd;
  10. + int counter = 0;
  11. + int c;
  12. + int is_cgroup = 0;
  13. +
  14. + outbuf[0]='\0';
  15. + snprintf(filename, sizeof filename, "/proc/%d/cgroup", pp->tgid);
  16. + fd = fopen(filename, "r");
  17. + if (likely(fd == NULL)) goto fail;
  18. + while (( (c = fgetc(fd)) != EOF) && (counter<665)) {
  19. + if (is_cgroup == 0) {
  20. + if (c == ':') {
  21. + is_cgroup = 1;
  22. + if (counter>0)
  23. + outbuf[counter++]=';';
  24. + }
  25. + }else
  26. + if ((c == '\n') || (c == '\0'))
  27. + is_cgroup = 0;
  28. + else
  29. + outbuf[counter++]=c;
  30. + }
  31. + outbuf[counter]='\0';
  32. + close(fd);
  33. + if (counter>0)
  34. + return counter;
  35. +fail:
  36. + outbuf[0] = '-';
  37. + outbuf[1] = '\0';
  38. + return 1;
  39. +}
  40. +
  41. #ifdef STATICLIB
  42. /****************** FLASK & seLinux security stuff **********************/
  43. // move the bulk of this to libproc sometime
  44. @@ -1291,6 +1325,7 @@ static const format_struct format_array[
  45. {"bsdtime", "TIME", pr_bsdtime, sr_nop, 6, 0, LNX, ET|RIGHT},
  46. {"c", "C", pr_c, sr_pcpu, 2, 0, SUN, ET|RIGHT},
  47. {"caught", "CAUGHT", pr_sigcatch, sr_nop, 9, 0, BSD, TO|SIGNAL}, /*sigcatch*/
  48. +{"cgroup", "CGROUP", pr_cgroup, sr_nop, 35, 0, LNX, PO|LEFT}, /* cgroups*/
  49. {"class", "CLS", pr_class, sr_sched, 3, 0, XXX, TO|LEFT},
  50. {"cls", "CLS", pr_class, sr_sched, 3, 0, HPU, TO|RIGHT}, /*says HPUX or RT*/
  51. {"cmaj_flt", "-", pr_nop, sr_cmaj_flt, 1, 0, LNX, AN|RIGHT},
  52. diff -up procps-3.2.7/ps/ps.1.pom procps-3.2.7/ps/ps.1
  53. --- procps-3.2.7/ps/ps.1.pom 2009-02-15 13:16:27.000000000 +0100
  54. +++ procps-3.2.7/ps/ps.1 2009-02-15 14:00:33.000000000 +0100
  55. @@ -908,6 +908,10 @@ width of the field, a 32 or 64 bits mask
  56. displayed. (alias\ \fBsig_catch\fR,\ \fBsigcatch\fR).
  57. T}
  58. +cgroup CGROUP T{
  59. +display control groups to which the process belonges.
  60. +t}
  61. +
  62. class CLS T{
  63. scheduling class of the process. (alias\ \fBpolicy\fR,\ \fBcls\fR).
  64. Field's possible values are: