]> granicus.if.org Git - procps-ng/commitdiff
ps: Add OOM and OOMADJ fields
authorCraig Small <csmall@dropbear.xyz>
Fri, 5 Mar 2021 06:22:29 +0000 (17:22 +1100)
committerCraig Small <csmall@dropbear.xyz>
Fri, 5 Mar 2021 06:22:29 +0000 (17:22 +1100)
top has had the OOMs and OOMa fields since 2011. Ten years its
probably time that ps had these fields added too.

ps output options have oom and oomadj for OOM Score and OOM Adjustment
respectively.

References:
 procps-ng/procps#198
 commit 367fd902dab64b51ba49709004b5011440e3105a
 https://www.freelists.org/post/procps/PATCH-12-Add-missed-oom-support-to-libproc

NEWS
ps/common.h
ps/global.c
ps/output.c
ps/ps.1

diff --git a/NEWS b/NEWS
index 6f9a3b677a65e1c0f8a5f29891cddb4eb9f33577..8fd047ebc849100103f317ae315e8cd2675c83bf 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ procps-ng-NEXT
 ---------------
   * Rename pwait to pidwait
   * library: renamed to libproc-2 and reset to 0:0:0
+  * ps: Add OOM and OOMADJ fields                          issue #198
 
 procps-ng-3.3.17
 ---------------
index 75be2aa3695f760345ca085c2789e4ef0d048a3a..08af46a27302062c6abd291450e8f4d1f744b015 100644 (file)
@@ -116,6 +116,8 @@ makEXT(NS_NET)
 makEXT(NS_PID)
 makEXT(NS_USER)
 makEXT(NS_UTS)
+makEXT(OOM_ADJ)
+makEXT(OOM_SCORE)
 makEXT(PRIORITY)
 makEXT(PRIORITY_RT)
 makEXT(PROCESSOR)
index c6b107b278e6624319eeb216ee26b68c1993adf5..72d32a4245380fc0b7415d7578c8c06aa8e721c2 100644 (file)
@@ -103,6 +103,8 @@ makREL(NS_NET)
 makREL(NS_PID)
 makREL(NS_USER)
 makREL(NS_UTS)
+makREL(OOM_ADJ)
+makREL(OOM_SCORE)
 makREL(PRIORITY)
 makREL(PRIORITY_RT)
 makREL(PROCESSOR)
index ac8f67dc4e5593921435574e4e2ae9fd5d2999f5..e7f3a2cee3ca2470fa2af9047b3e4fc62ce5877d 100644 (file)
@@ -704,6 +704,15 @@ setREL2(NICE,SCHED_CLASS)
   return snprintf(outbuf, COLWID, "%d", rSv(NICE, s_int, pp));
 }
 
+static int pr_oom_adj(char *restrict const outbuf, const proc_t *restrict const pp){
+setREL1(OOM_ADJ)
+  return snprintf(outbuf, COLWID, "%d", rSv(OOM_ADJ, s_int, pp));
+}
+
+static int pr_oom(char *restrict const outbuf, const proc_t *restrict const pp){
+setREL1(OOM_SCORE)
+  return snprintf(outbuf, COLWID, "%d", rSv(OOM_SCORE, s_int, pp));
+}
 // HP-UX   "cls": RT RR RR2 ???? HPUX FIFO KERN
 // Solaris "class": SYS TS FX IA RT FSS (FIFO is RR w/ Inf quant)
 //                  FIFO+RR share RT; FIFO has Inf quant
@@ -1634,6 +1643,8 @@ static const format_struct format_array[] = { /*
 {"numa",      "NUMA",    pr_numa,          PIDS_PROCESSOR_NODE,      4,    XXX,  AN|RIGHT},
 {"nvcsw",     "VCSW",    pr_nop,           PIDS_noop,                5,    XXX,  AN|RIGHT},
 {"nwchan",    "WCHAN",   pr_nop,           PIDS_noop,                6,    XXX,  TO|RIGHT},
+{"oom",       "OOM",     pr_oom,           PIDS_OOM_SCORE,           4,    XXX,  TO|RIGHT},
+{"oomadj",    "OOMADJ",  pr_oom_adj,       PIDS_OOM_ADJ,             5,    XXX,  TO|RIGHT},
 {"opri",      "PRI",     pr_opri,          PIDS_PRIORITY,            3,    SUN,  TO|RIGHT},
 {"osz",       "SZ",      pr_nop,           PIDS_noop,                2,    SUN,  PO|RIGHT},
 {"oublk",     "OUBLK",   pr_nop,           PIDS_noop,                5,    BSD,  AN|RIGHT}, /*oublock*/
diff --git a/ps/ps.1 b/ps/ps.1
index 27923092809f569ada9813b928c4b112663e268c..8678123f9f0f06522aeb8d9c72188402a646d681 100644 (file)
--- a/ps/ps.1
+++ b/ps/ps.1
@@ -4,7 +4,7 @@
 .\" Quick hack conversion by Albert Cahalan, 1998.
 .\" Licensed under version 2 of the Gnu General Public License.
 .\"
-.TH PS "1" "2020-06-04" "procps-ng" "User Commands"
+.TH PS "1" "2021-03-05" "procps-ng" "User Commands"
 .\"
 .\" To render this page:
 .\"    groff -t -b -man -X -P-resolution -P100 -Tps ps.1 &
@@ -1421,6 +1421,17 @@ address of the kernel function where the process is sleeping (use
 if you want the kernel function name).
 T}
 
+oom    OOM     T{
+Out of Memory Score. The value, ranging from 0 to +1000, used to select
+task(s) to kill when memory is exhausted.
+T}
+
+oomadj OOMADJ  T{
+Out of Memory Adjustment Factor. The value is added to the current out of
+memory score which is then used to determine which task to kill when memory
+is exhausted.
+T}
+
 ouid   OWNER   T{
 displays the Unix user identifier of the owner of the session of a process,
 if systemd support has been included.