ps displays cgroup

Author: Swann Perarnau <swann.perarnau@imag.fr>
Bug-Debian: http://bugs.debian.org/469669
Reviewed-by: Craig Small <csmall@debian.org>
This commit is contained in:
Jan Görig
2010-12-16 10:23:49 +01:00
parent 0232430bef
commit af25453d9a
5 changed files with 50 additions and 7 deletions

View File

@@ -631,6 +631,17 @@ static proc_t* simple_readproc(PROCTAB *restrict const PT, proc_t *restrict cons
p->environ = file2strvec(path, "environ");
else
p->environ = NULL;
if(linux_version_code>=LINUX_VERSION(2,6,24) && (flags & PROC_FILLCGROUP)) {
p->cgroup = file2strvec(path, "cgroup"); /* read /proc/#/cgroup */
if(p->cgroup && *p->cgroup) {
int i = strlen(*p->cgroup);
if( (*p->cgroup)[i-1]=='\n' )
(*p->cgroup)[i-1] = ' '; //little hack to remove trailing \n
}
}
else
p->cgroup = NULL;
return p;
next_proc:
@@ -719,7 +730,7 @@ static proc_t* simple_readtask(PROCTAB *restrict const PT, const proc_t *restric
t->cmdline = p->cmdline; // better not free these until done with all threads!
t->environ = p->environ;
#endif
t->cgroup = p->cgroup;
t->ppid = p->ppid; // ought to put the per-task ppid somewhere
return t;
@@ -929,6 +940,8 @@ void freeproc(proc_t* p) {
free((void*)*p->cmdline);
if (p->environ)
free((void*)*p->environ);
if (p->cgroup)
free((void*)*p->cgroup);
free(p);
}

View File

@@ -140,6 +140,7 @@ typedef struct proc_t {
tpgid, // stat terminal process group id
exit_signal, // stat might not be SIGCHLD
processor; // stat current (or most recent?) CPU
char **cgroup; // cgroup current cgroup, looks like a classic filepath
} proc_t;
// PROCTAB: data structure holding the persistent information readproc needs
@@ -237,8 +238,9 @@ extern proc_t * get_proc_stats(pid_t pid, proc_t *p);
#define PROC_FILLSTAT 0x0040 // read stat -- currently unconditional
#define PROC_FILLWCHAN 0x0080 // look up WCHAN name
#define PROC_FILLARG 0x0100 // alloc and fill in `cmdline'
#define PROC_FILLCGROUP 0x0200 // alloc and fill in `cgroup`
#define PROC_LOOSE_TASKS 0x0200 // threat threads as if they were processes
#define PROC_LOOSE_TASKS 0x2000 // threat threads as if they were processes
// Obsolete, consider only processes with one of the passed:
#define PROC_PID 0x1000 // process id numbers ( 0 terminated)