summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Fink <werner@suse.de>2011-04-15 15:52:40 +0200
committerWerner Fink <werner@suse.de>2011-04-15 15:52:40 +0200
commite6469849246cd1eabf02c3ef7d9e2a601a190fe5 (patch)
treefb2d3cdc9b071f3ff35cd5a3c78da4a7f803359e
parent3ec6a27e8a0cfb8019560f54edc156385fcd911d (diff)
downloadprocps-ng-e6469849246cd1eabf02c3ef7d9e2a601a190fe5.tar.gz
Add missed oom support to libproc
Add missed oom support to libproc Signed-off-by: Werner Fink <werner@suse.de>
-rw-r--r--proc/readproc.c22
-rw-r--r--proc/readproc.h5
2 files changed, 26 insertions, 1 deletions
diff --git a/proc/readproc.c b/proc/readproc.c
index 890e77a..e12e284 100644
--- a/proc/readproc.c
+++ b/proc/readproc.c
@@ -365,6 +365,19 @@ LEAVE(0x220);
}
///////////////////////////////////////////////////////////////////////
+#ifdef ZAP_SUSEONLY
+static void oomscore2proc(const char* S, proc_t *restrict P)
+{
+ sscanf(S, "%d", &P->oom_score);
+}
+
+static void oomadj2proc(const char* S, proc_t *restrict P)
+{
+ sscanf(S, "%d", &P->oom_adj);
+}
+#endif
+///////////////////////////////////////////////////////////////////////
+
// Reads /proc/*/stat files, being careful not to trip over processes with
// names like ":-) 1 2 3 4 5 6".
@@ -637,7 +650,14 @@ static proc_t* simple_readproc(PROCTAB *restrict const PT, proc_t *restrict cons
p->environ = file2strvec(path, "environ");
else
p->environ = NULL;
-
+#ifdef ZAP_SUSEONLY
+ if (unlikely(flags & PROC_FILLOOM)) {
+ if (likely( file2str(path, "oom_score", sbuf, sizeof sbuf) != -1 ))
+ oomscore2proc(sbuf, p);
+ if (likely( file2str(path, "oom_adj", sbuf, sizeof sbuf) != -1 ))
+ oomadj2proc(sbuf, p);
+ } /* struct has been zeroed out before, so no worries about clearing garbage here */
+#endif
if(linux_version_code>=LINUX_VERSION(2,6,24) && (flags & PROC_FILLCGROUP))
p->cgroup = file2strvec(path, "cgroup"); /* read /proc/#/cgroup */
else
diff --git a/proc/readproc.h b/proc/readproc.h
index 0b2c46a..3404c19 100644
--- a/proc/readproc.h
+++ b/proc/readproc.h
@@ -140,6 +140,10 @@ typedef struct proc_t {
tpgid, // stat terminal process group id
exit_signal, // stat might not be SIGCHLD
processor; // stat current (or most recent?) CPU
+#ifdef ZAP_SUSEONLY
+ int oom_score, // oom_score (badness for OOM killer)
+ oom_adj; // oom_adj (adjustment to OOM score)
+#endif
char **cgroup; // cgroup current cgroup, looks like a classic filepath
} proc_t;
@@ -239,6 +243,7 @@ extern proc_t * get_proc_stats(pid_t pid, proc_t *p);
#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_FILLOOM 0x0400 // alloc and fill in oom_score, oom_adj
#define PROC_LOOSE_TASKS 0x2000 // threat threads as if they were processes