From 2119750a51c836a3053ee614a0087304ba08287d Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Sun, 11 Feb 2018 03:33:33 -0600 Subject: [PATCH] top: change to exploit a newly added UID used at login In addition to exploiting the login user ID provision, the following miscellaneous changes are also included: . unnecessary braces have been eliminated from an 'if' . a comment with case EU_CPU: was corrected to 's_int' and the associated block of code relocated accordingly . case EU_CPN: wasn't shared with other enumerators so reference to 'i' was changed to that actual enumerator . case EU_SGN: wasn't shared with other enumerators so reference to 'i' was changed to that actual enumerator Signed-off-by: Jim Warner --- top/top.1 | 109 ++++++++++++++++++++++++++------------------------ top/top.c | 40 ++++++++++-------- top/top.h | 1 + top/top_nls.c | 3 ++ 4 files changed, 84 insertions(+), 69 deletions(-) diff --git a/top/top.1 b/top/top.1 index 4ac4ff58..7f9170e3 100644 --- a/top/top.1 +++ b/top/top.1 @@ -67,7 +67,7 @@ . .\" Document ///////////////////////////////////////////////////////////// .\" ---------------------------------------------------------------------- -.TH TOP 1 "January 2018" "procps-ng" "User Commands" +.TH TOP 1 "February 2018" "procps-ng" "User Commands" .\" ---------------------------------------------------------------------- .\" ---------------------------------------------------------------------- @@ -712,12 +712,17 @@ The\fI effective\fR group ID. The\fI effective\fR group name. .TP 4 -12.\fB LXC \*(Em Lxc Container Name \fR +12.\fB LOGID \*(Em Login User Id \fR +The user ID used at\fI login\fR. +When -1 is displayed it means this information is not available. + +.TP 4 +13.\fB LXC \*(Em Lxc Container Name \fR The name of the lxc container within which a task is running. If a process is not running inside a container, a dash (`\-') will be shown. .TP 4 -13.\fB NI \*(Em Nice Value \fR +14.\fB NI \*(Em Nice Value \fR The nice value of the task. A negative nice value means higher priority, whereas a positive nice value means lower priority. @@ -725,26 +730,26 @@ Zero in this field simply means priority will not be adjusted in determining a task's dispatch-ability. .TP 4 -14.\fB NU \*(Em Last known NUMA node \fR +15.\fB NU \*(Em Last known NUMA node \fR A number representing the NUMA node associated with the last used processor (`P'). When -1 is displayed it means that NUMA information is not available. \*(XC `'2' and `3' \*(CIs for additional NUMA provisions affecting the \*(SA. .TP 4 -15.\fB OOMa \*(Em Out of Memory Adjustment Factor \fR +16.\fB OOMa \*(Em Out of Memory Adjustment Factor \fR The value, ranging from -1000 to +1000, added to the current out of memory score (OOMs) which is then used to determine which task to kill when memory is exhausted. .TP 4 -16.\fB OOMs \*(Em Out of Memory Score \fR +17.\fB OOMs \*(Em Out of Memory Score \fR The value, ranging from 0 to +1000, used to select task(s) to kill when memory is exhausted. Zero translates to `never kill' whereas 1000 means `always kill'. .TP 4 -17.\fB P \*(Em Last used \*(PU (SMP) \fR +18.\fB P \*(Em Last used \*(PU (SMP) \fR A number representing the last used processor. In a true SMP environment this will likely change frequently since the kernel intentionally uses weak affinity. @@ -753,7 +758,7 @@ processes to change \*(PUs more often (because of the extra demand for \*(Pu time). .TP 4 -18.\fB PGRP \*(Em Process Group Id \fR +19.\fB PGRP \*(Em Process Group Id \fR Every process is member of a unique process group which is used for distribution of signals and by terminals to arbitrate requests for their input and output. @@ -763,7 +768,7 @@ By convention, this value equals the process ID (\*(Xa PID) of the first member of a process group, called the process group leader. .TP 4 -19.\fB PID \*(Em Process Id \fR +20.\fB PID \*(Em Process Id \fR The task's unique process ID, which periodically wraps, though never restarting at zero. In kernel terms, it is a dispatchable entity defined by a task_struct. @@ -774,11 +779,11 @@ a thread group ID for the thread group leader (\*(Xa TGID); and a TTY process group ID for the process group leader (\*(Xa TPGID). .TP 4 -20.\fB PPID \*(Em Parent Process Id \fR +21.\fB PPID \*(Em Parent Process Id \fR The process ID (pid) of a task's parent. .TP 4 -21.\fB PR \*(Em Priority \fR +22.\fB PR \*(Em Priority \fR The scheduling priority of the task. If you see `rt' in this field, it means the task is running under real time scheduling priority. @@ -788,7 +793,7 @@ the operating itself was not preemptible. And while the 2.6 kernel can be made mostly preemptible, it is not always so. .TP 4 -22.\fB RES \*(Em Resident Memory Size (KiB) \fR +23.\fB RES \*(Em Resident Memory Size (KiB) \fR A subset of the virtual address space (VIRT) representing the non-swapped \*(MP a task is currently using. It is also the sum of the RSan, RSfd and RSsh fields. @@ -803,35 +808,35 @@ modified, act as a dedicated \*(MS and thus will never impact SWAP. \*(XX. .TP 4 -23.\fB RSan \*(Em Resident Anonymous Memory Size (KiB) \fR +24.\fB RSan \*(Em Resident Anonymous Memory Size (KiB) \fR A subset of resident memory (RES) representing private pages not mapped to a file. .TP 4 -24.\fB RSfd \*(Em Resident File-Backed Memory Size (KiB) \fR +25.\fB RSfd \*(Em Resident File-Backed Memory Size (KiB) \fR A subset of resident memory (RES) representing the implicitly shared pages supporting program images and shared libraries. It also includes explicit file mappings, both private and shared. .TP 4 -25.\fB RSlk \*(Em Resident Locked Memory Size (KiB) \fR +26.\fB RSlk \*(Em Resident Locked Memory Size (KiB) \fR A subset of resident memory (RES) which cannot be swapped out. .TP 4 -26.\fB RSsh \*(Em Resident Shared Memory Size (KiB) \fR +27.\fB RSsh \*(Em Resident Shared Memory Size (KiB) \fR A subset of resident memory (RES) representing the explicitly shared anonymous shm*/mmap pages. .TP 4 -27.\fB RUID \*(Em Real User Id \fR +28.\fB RUID \*(Em Real User Id \fR The\fI real\fR user ID. .TP 4 -28.\fB RUSER \*(Em Real User Name \fR +29.\fB RUSER \*(Em Real User Name \fR The\fI real\fR user name. .TP 4 -29.\fB S \*(Em Process Status \fR +30.\fB S \*(Em Process Status \fR The status of the task which can be one of: \fBD\fR = uninterruptible sleep \fBI\fR = idle @@ -847,7 +852,7 @@ Even without a true SMP machine, you may see numerous tasks in this state depending on \*(We's delay interval and nice value. .TP 4 -30.\fB SHR \*(Em Shared Memory Size (KiB) \fR +31.\fB SHR \*(Em Shared Memory Size (KiB) \fR A subset of resident memory (RES) that may be used by other processes. It will include shared anonymous pages and shared file-backed pages. It also includes private pages mapped to files representing @@ -856,7 +861,7 @@ program images and shared libraries. \*(XX. .TP 4 -31.\fB SID \*(Em Session Id \fR +32.\fB SID \*(Em Session Id \fR A session is a collection of process groups (\*(Xa PGRP), usually established by the login shell. A newly forked process joins the session of its creator. @@ -865,11 +870,11 @@ member of the session, called the session leader, which is usually the login shell. .TP 4 -32.\fB SUID \*(Em Saved User Id \fR +33.\fB SUID \*(Em Saved User Id \fR The\fI saved\fR user ID. .TP 4 -33.\fB SUPGIDS \*(Em Supplementary Group IDs \fR +34.\fB SUPGIDS \*(Em Supplementary Group IDs \fR The IDs of any supplementary group(s) established at login or inherited from a task's parent. They are displayed in a comma delimited list. @@ -882,7 +887,7 @@ Even so, such variable width fields could still suffer truncation. any truncated data. .TP 4 -34.\fB SUPGRPS \*(Em Supplementary Group Names \fR +35.\fB SUPGRPS \*(Em Supplementary Group Names \fR The names of any supplementary group(s) established at login or inherited from a task's parent. They are displayed in a comma delimited list. @@ -895,24 +900,24 @@ Even so, such variable width fields could still suffer truncation. any truncated data. .TP 4 -35.\fB SUSER \*(Em Saved User Name \fR +36.\fB SUSER \*(Em Saved User Name \fR The\fI saved\fR user name. .TP 4 -36.\fB SWAP \*(Em Swapped Size (KiB) \fR +37.\fB SWAP \*(Em Swapped Size (KiB) \fR The formerly resident portion of a task's address space written to the \*(MS when \*(MP becomes over committed. \*(XX. .TP 4 -37.\fB TGID \*(Em Thread Group Id \fR +38.\fB TGID \*(Em Thread Group Id \fR The ID of the thread group to which a task belongs. It is the PID of the thread group leader. In kernel terms, it represents those tasks that share an mm_struct. .TP 4 -38.\fB TIME \*(Em \*(PU Time \fR +39.\fB TIME \*(Em \*(PU Time \fR Total \*(PU time the task has used since it started. When Cumulative mode is \*O, each process is listed with the \*(Pu time that it and its dead children have used. @@ -920,19 +925,19 @@ You toggle Cumulative mode with `S', which is both a \*(CO and an \*(CI. \*(XC `S' \*(CI for additional information regarding this mode. .TP 4 -39.\fB TIME+ \*(Em \*(PU Time, hundredths \fR +40.\fB TIME+ \*(Em \*(PU Time, hundredths \fR The same as TIME, but reflecting more granularity through hundredths of a second. .TP 4 -40.\fB TPGID \*(Em Tty Process Group Id \fR +41.\fB TPGID \*(Em Tty Process Group Id \fR The process group ID of the foreground process for the connected tty, or \-1 if a process is not connected to a terminal. By convention, this value equals the process ID (\*(Xa PID) of the process group leader (\*(Xa PGRP). .TP 4 -41.\fB TTY \*(Em Controlling Tty \fR +42.\fB TTY \*(Em Controlling Tty \fR The name of the controlling terminal. This is usually the device (serial port, pty, etc.) from which the process was started, and which it uses for input or output. @@ -940,22 +945,22 @@ However, a task need not be associated with a terminal, in which case you'll see `?' displayed. .TP 4 -42.\fB UID \*(Em User Id \fR +43.\fB UID \*(Em User Id \fR The\fI effective\fR user ID of the task's owner. .TP 4 -43.\fB USED \*(Em Memory in Use (KiB) \fR +44.\fB USED \*(Em Memory in Use (KiB) \fR This field represents the non-swapped \*(MP a task is using (RES) plus the swapped out portion of its address space (SWAP). \*(XX. .TP 4 -44.\fB USER \*(Em User Name \fR +45.\fB USER \*(Em User Name \fR The\fI effective\fR user name of the task's owner. .TP 4 -45.\fB VIRT \*(Em Virtual Memory Size (KiB) \fR +46.\fB VIRT \*(Em Virtual Memory Size (KiB) \fR The total amount of \*(MV used by the task. It includes all code, data and shared libraries plus pages that have been swapped out and pages that have been mapped but not used. @@ -963,13 +968,13 @@ swapped out and pages that have been mapped but not used. \*(XX. .TP 4 -46.\fB WCHAN \*(Em Sleeping in Function \fR +47.\fB WCHAN \*(Em Sleeping in Function \fR This field will show the name of the kernel function in which the task is currently sleeping. Running tasks will display a dash (`\-') in this column. .TP 4 -47.\fB nDRT \*(Em Dirty Pages Count \fR +48.\fB nDRT \*(Em Dirty Pages Count \fR The number of pages that have been modified since they were last written to \*(AS. Dirty pages must be written to \*(AS before the corresponding physical @@ -978,7 +983,7 @@ memory location can be used for some other virtual page. This field was deprecated with linux 2.6 and is always zero. .TP 4 -48.\fB nMaj \*(Em Major Page Fault Count \fR +49.\fB nMaj \*(Em Major Page Fault Count \fR The number of\fB major\fR page faults that have occurred for a task. A page fault occurs when a process attempts to read from or write to a virtual page that is not currently present in its address space. @@ -986,7 +991,7 @@ A major page fault is when \*(AS access is involved in making that page available. .TP 4 -49.\fB nMin \*(Em Minor Page Fault count \fR +50.\fB nMin \*(Em Minor Page Fault count \fR The number of\fB minor\fR page faults that have occurred for a task. A page fault occurs when a process attempts to read from or write to a virtual page that is not currently present in its address space. @@ -994,50 +999,50 @@ A minor page fault does not involve \*(AS access in making that page available. .TP 4 -50.\fB nTH \*(Em Number of Threads \fR +51.\fB nTH \*(Em Number of Threads \fR The number of threads associated with a process. .TP 4 -51.\fB nsIPC \*(Em IPC namespace \fR +52.\fB nsIPC \*(Em IPC namespace \fR The Inode of the namespace used to isolate interprocess communication (IPC) resources such as System V IPC objects and POSIX message queues. .TP 4 -52.\fB nsMNT \*(Em MNT namespace \fR +53.\fB nsMNT \*(Em MNT namespace \fR The Inode of the namespace used to isolate filesystem mount points thus offering different views of the filesystem hierarchy. .TP 4 -53.\fB nsNET \*(Em NET namespace \fR +54.\fB nsNET \*(Em NET namespace \fR The Inode of the namespace used to isolate resources such as network devices, IP addresses, IP routing, port numbers, etc. .TP 4 -54.\fB nsPID \*(Em PID namespace \fR +55.\fB nsPID \*(Em PID namespace \fR The Inode of the namespace used to isolate process ID numbers meaning they need not remain unique. Thus, each such namespace could have its own `init/systemd' (PID #1) to manage various initialization tasks and reap orphaned child processes. .TP 4 -55.\fB nsUSER \*(Em USER namespace \fR +56.\fB nsUSER \*(Em USER namespace \fR The Inode of the namespace used to isolate the user and group ID numbers. Thus, a process could have a normal unprivileged user ID outside a user namespace while having a user ID of 0, with full root privileges, inside that namespace. .TP 4 -56.\fB nsUTS \*(Em UTS namespace \fR +57.\fB nsUTS \*(Em UTS namespace \fR The Inode of the namespace used to isolate hostname and NIS domain name. UTS simply means "UNIX Time-sharing System". .TP 4 -57.\fB vMj \*(Em Major Page Fault Count Delta\fR +58.\fB vMj \*(Em Major Page Fault Count Delta\fR The number of\fB major\fR page faults that have occurred since the last update (see nMaj). .TP 4 -58.\fB vMn \*(Em Minor Page Fault Count Delta\fR +59.\fB vMn \*(Em Minor Page Fault Count Delta\fR The number of\fB minor\fR page faults that have occurred since the last update (see nMin). @@ -1308,10 +1313,10 @@ This \*(CI can be used to alter the widths of the following fields: .nf \fI field default field default field default \fR GID 5 GROUP 8 WCHAN 10 - RUID 5 LXC 8 nsIPC 10 - SUID 5 RUSER 8 nsMNT 10 - UID 5 SUSER 8 nsNET 10 - TTY 8 nsPID 10 + LOGID 5 LXC 8 nsIPC 10 + RUID 5 RUSER 8 nsMNT 10 + SUID 5 SUSER 8 nsNET 10 + UID 5 TTY 8 nsPID 10 USER 8 nsUSER 10 nsUTS 10 .fi diff --git a/top/top.c b/top/top.c index 5ad71dc3..617c67ab 100644 --- a/top/top.c +++ b/top/top.c @@ -1703,7 +1703,8 @@ static struct { { 6, SK_Kb, A_right, -1, PIDS_VM_RSS_SHARED }, // ul_int EU_RZS { -1, -1, A_left, -1, PIDS_CGNAME }, // str EU_CGN { 0, -1, A_right, -1, PIDS_PROCESSOR_NODE }, // s_int EU_NMA -#define eu_LAST EU_NMA + { 5, -1, A_right, -1, PIDS_ID_LOGIN }, // s_int EU_LID +#define eu_LAST EU_LID // xtra Fieldstab 'pseudo pflag' entries for the newlib interface . . . . . . . #define eu_CMDLINE eu_LAST +1 #define eu_TICS_ALL_C eu_LAST +2 @@ -2243,7 +2244,8 @@ static void zap_fieldstab (void) { = wtab[EU_GID].watx = wtab[EU_GRP].watx = wtab[EU_TTY].watx = wtab[EU_WCH].watx = wtab[EU_NS1].watx = wtab[EU_NS2].watx = wtab[EU_NS3].watx = wtab[EU_NS4].watx = wtab[EU_NS5].watx - = wtab[EU_NS6].watx = wtab[EU_LXC].watx = +1; + = wtab[EU_NS6].watx = wtab[EU_LXC].watx = wtab[EU_LID].watx + = +1; /* establish translatable header 'column' requirements and ensure .width reflects the widest value */ for (i = 0; i < EU_MAXPFLGS; i++) { @@ -5192,6 +5194,10 @@ static const char *task_show (const WIN_t *q, struct pids_stack *p) { case EU_STA: cp = make_chr(rSv(EU_STA, s_ch), W, Js); break; + /* s_int, make_num with auto width */ + case EU_LID: + cp = make_num(rSv(EU_LID, s_int), W, Jn, EU_LID, 0); + break; /* s_int, make_num without auto width */ case EU_NMA: case EU_PGD: @@ -5216,23 +5222,12 @@ static const char *task_show (const WIN_t *q, struct pids_stack *p) { break; /* s_int, make_num or make_str */ case EU_PRI: - if (-99 > rSv(EU_PRI, s_int) || 999 < rSv(EU_PRI, s_int)) { + if (-99 > rSv(EU_PRI, s_int) || 999 < rSv(EU_PRI, s_int)) cp = make_str("rt", W, Jn, AUTOX_NO); - } else + else cp = make_num(rSv(EU_PRI, s_int), W, Jn, AUTOX_NO, 0); break; - /* u_int, make_num without auto width */ - case EU_CPN: - cp = make_num(rSv(i, u_int), W, Jn, AUTOX_NO, 0); - break; - /* u_int, make_num with auto width */ - case EU_GID: - case EU_UED: - case EU_URD: - case EU_USD: - cp = make_num(rSv(i, u_int), W, Jn, i, 0); - break; - /* u_int, scale_pcnt with special handling */ + /* s_int, scale_pcnt with special handling */ case EU_CPU: { float u = (float)rSv(EU_CPU, s_int) * Frame_etscale; int n = rSv(EU_THD, s_int); @@ -5243,6 +5238,17 @@ static const char *task_show (const WIN_t *q, struct pids_stack *p) { cp = scale_pcnt(u, W, Jn); } break; + /* u_int, make_num without auto width */ + case EU_CPN: + cp = make_num(rSv(EU_CPN, u_int), W, Jn, AUTOX_NO, 0); + break; + /* u_int, make_num with auto width */ + case EU_GID: + case EU_UED: + case EU_URD: + case EU_USD: + cp = make_num(rSv(i, u_int), W, Jn, i, 0); + break; /* ul_int, make_num with auto width and zero supression */ case EU_NS1: case EU_NS2: @@ -5311,7 +5317,7 @@ static const char *task_show (const WIN_t *q, struct pids_stack *p) { break; /* str, make_str_utf8 with varialbe width */ case EU_SGN: - varUTF8(rSv(i, str)); + varUTF8(rSv(EU_SGN, str)); break; /* str, make_str with varialbe width + additional decoration */ case EU_CMD: diff --git a/top/top.h b/top/top.h index 379f9628..f279b8a9 100644 --- a/top/top.h +++ b/top/top.h @@ -180,6 +180,7 @@ enum pflag { EU_RZA, EU_RZF, EU_RZL, EU_RZS, EU_CGN, EU_NMA, + EU_LID, #ifdef USE_X_COLHDR // not really pflags, used with tbl indexing EU_MAXPFLGS diff --git a/top/top_nls.c b/top/top_nls.c index 5db180f3..08008ffb 100644 --- a/top/top_nls.c +++ b/top/top_nls.c @@ -305,6 +305,9 @@ static void build_two_nlstabs (void) { /* Translation Hint: maximum 'NU' = 2 */ Head_nlstab[EU_NMA] = _("NU"); Desc_nlstab[EU_NMA] = _("Last Used NUMA node"); +/* Translation Hint: maximum 'LOGID' = 5 + */ + Head_nlstab[EU_LID] = _("LOGID"); + Desc_nlstab[EU_LID] = _("Login User Id"); }