diff --git a/Process.c b/Process.c index 695e1447..f154657a 100644 --- a/Process.c +++ b/Process.c @@ -81,6 +81,9 @@ typedef enum ProcessField_ { #ifdef HAVE_CGROUP CGROUP, #endif + #ifdef HAVE_OOM + OOM, + #endif IO_PRIORITY, LAST_PROCESSFIELD } ProcessField; @@ -177,6 +180,9 @@ typedef struct Process_ { #ifdef HAVE_CGROUP char* cgroup; #endif + #ifdef HAVE_OOM + unsigned int oom; + #endif } Process; }*/ @@ -202,6 +208,9 @@ const char *Process_fieldNames[] = { #endif #ifdef HAVE_CGROUP "CGROUP", +#endif +#ifdef HAVE_OOM + "OOM", #endif "IO_PRIORITY", "*** report bug! ***" @@ -228,6 +237,9 @@ const int Process_fieldFlags[] = { #endif #ifdef HAVE_CGROUP PROCESS_FLAG_CGROUP, +#endif +#ifdef HAVE_OOM + 0, #endif PROCESS_FLAG_IOPRIO }; @@ -253,6 +265,9 @@ const char *Process_fieldTitles[] = { #endif #ifdef HAVE_CGROUP " CGROUP ", +#endif +#ifdef HAVE_OOM + " OOM ", #endif "IO ", "*** report bug! ***" @@ -276,6 +291,9 @@ void Process_getMaxPid() { Process_fieldTitles[TGID] = " TGID "; Process_fieldTitles[PGRP] = " PGRP "; Process_fieldTitles[SESSION] = " SESN "; + #ifdef HAVE_OOM + Process_fieldTitles[OOM] = " OOM "; + #endif Process_pidFormat = "%7u "; Process_tpgidFormat = "%7d "; } else { @@ -285,6 +303,9 @@ void Process_getMaxPid() { Process_fieldTitles[TGID] = " TGID "; Process_fieldTitles[PGRP] = " PGRP "; Process_fieldTitles[SESSION] = " SESN "; + #ifdef HAVE_OOM + Process_fieldTitles[OOM] = " OOM "; + #endif Process_pidFormat = "%5u "; Process_tpgidFormat = "%5d "; } @@ -545,6 +566,9 @@ static void Process_writeField(Process* this, RichString* str, ProcessField fiel #ifdef HAVE_CGROUP case CGROUP: snprintf(buffer, n, "%-10s ", this->cgroup); break; #endif + #ifdef HAVE_OOM + case OOM: snprintf(buffer, n, Process_pidFormat, this->oom); break; + #endif case IO_PRIORITY: { int klass = IOPriority_class(this->ioPriority); if (klass == IOPRIO_CLASS_NONE) { @@ -814,6 +838,10 @@ int Process_compare(const void* v1, const void* v2) { case CGROUP: return strcmp(p1->cgroup ? p1->cgroup : "", p2->cgroup ? p2->cgroup : ""); #endif + #ifdef HAVE_OOM + case OOM: + return (p1->oom - p2->oom); + #endif case IO_PRIORITY: return Process_effectiveIOPriority(p1) - Process_effectiveIOPriority(p2); default: diff --git a/Process.h b/Process.h index a24c7c04..d1a39e41 100644 --- a/Process.h +++ b/Process.h @@ -60,6 +60,9 @@ typedef enum ProcessField_ { #ifdef HAVE_CGROUP CGROUP, #endif + #ifdef HAVE_OOM + OOM, + #endif IO_PRIORITY, LAST_PROCESSFIELD } ProcessField; @@ -156,6 +159,9 @@ typedef struct Process_ { #ifdef HAVE_CGROUP char* cgroup; #endif + #ifdef HAVE_OOM + unsigned int oom; + #endif } Process; diff --git a/ProcessList.c b/ProcessList.c index b470344c..a5b9568b 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -660,6 +660,28 @@ static void ProcessList_readVServerData(Process* process, const char* dirname, c #endif +#ifdef HAVE_OOM + +static void ProcessList_readOomData(Process* process, const char* dirname, const char* name) { + char filename[MAX_NAME+1]; + snprintf(filename, MAX_NAME, "%s/%s/oom_score", dirname, name); + FILE* file = fopen(filename, "r"); + if (!file) + return; + char buffer[256]; + if (!fgets(buffer, 255, file)) { + return; + } + unsigned int oom; + int ok = sscanf(buffer, "%u", &oom); + if (ok >= 1) { + process->oom = oom; + } + fclose(file); +} + +#endif + static bool ProcessList_readCmdlineFile(Process* process, const char* dirname, const char* name) { if (Process_isKernelThread(process)) return true; @@ -784,6 +806,10 @@ static bool ProcessList_processEntries(ProcessList* this, const char* dirname, P ProcessList_readVServerData(process, dirname, name); #endif + #ifdef HAVE_OOM + ProcessList_readOomData(process, dirname, name); + #endif + if (! ProcessList_readCmdlineFile(process, dirname, name)) goto errorReadingProcess; diff --git a/ProcessList.h b/ProcessList.h index cabd68d6..437c57f4 100644 --- a/ProcessList.h +++ b/ProcessList.h @@ -172,6 +172,10 @@ void ProcessList_sort(ProcessList* this); #endif +#ifdef HAVE_OOM + +#endif + void ProcessList_scan(ProcessList* this); diff --git a/configure.ac b/configure.ac index 45c0b53b..ef57ebdc 100644 --- a/configure.ac +++ b/configure.ac @@ -145,5 +145,10 @@ then AC_CHECK_HEADERS([hwloc.h],[:], [missing_headers="$missing_headers $ac_header"]) fi +AC_ARG_ENABLE(oom, [AC_HELP_STRING([--enable-oom], [enable OOM score reporting])], ,enable_oom="no") +if test "x$enable_oom" = xyes; then + AC_DEFINE(HAVE_OOM, 1, [Define if OOM score support enabled.]) +fi + AC_CONFIG_FILES([Makefile htop.1]) AC_OUTPUT diff --git a/htop.1.in b/htop.1.in index e94d4086..5b2d754e 100644 --- a/htop.1.in +++ b/htop.1.in @@ -313,6 +313,9 @@ OpenVZ process ID. .B VXID VServer process ID. .TP +.B OOM +OOM killer score. +.TP .B All other flags Currently unsupported (always displays '-').