From: Jim Warner Date: Sun, 3 Jul 2016 05:00:00 +0000 (-0500) Subject: misc: adapted others to that new proc_t 'cgname' field X-Git-Tag: v3.3.12~17 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eca9168617a6bd6218b17b44d3673610cb69e803;p=procps-ng misc: adapted others to that new proc_t 'cgname' field This patch adapts the ps program to a newly add proc_t field and provides for new support in that top program along with his man document (ps was already ok there). Signed-off-by: Jim Warner --- diff --git a/ps/output.c b/ps/output.c index 305e6e30..42c04cf6 100644 --- a/ps/output.c +++ b/ps/output.c @@ -104,26 +104,6 @@ static int sr_cgroup(const proc_t* a, const proc_t* b) return strcmp(*a->cgroup, *b->cgroup); } -static int sr_cgname(const proc_t* a, const proc_t* b) -{ - char *aname, *bname; - /* This is a "vector" of one */ - if (*a->cgroup == NULL || *b->cgroup == NULL) - return 0; - aname = strstr(*a->cgroup, ":name="); - bname = strstr(*b->cgroup, ":name="); - /* check for missing names, they win */ - if (aname == NULL || aname[6] == '\0') { - if (bname == NULL || bname[6] == '\0') - return 0; - return -1; - } else if (bname == NULL || bname[6] == '\0') - return 1; - return strcmp(aname+6,bname+6); - -} - - #define CMP_STR(NAME) \ static int sr_ ## NAME(const proc_t* P, const proc_t* Q) { \ return strcmp(P->NAME, Q->NAME); \ @@ -255,6 +235,7 @@ CMP_NS(userns, USERNS); CMP_NS(utsns, UTSNS); CMP_STR(lxcname) +CMP_STR(cgname) /* approximation to: kB of address space that could end up in swap */ static int sr_swapable(const proc_t* P, const proc_t* Q) { @@ -464,27 +445,18 @@ static int pr_comm(char *restrict const outbuf, const proc_t *restrict const pp) return max_rightward-rightward; } -static int pr_cgroup(char *restrict const outbuf,const proc_t *restrict const pp) { +static int pr_cgname(char *restrict const outbuf, const proc_t *restrict const pp){ int rightward = max_rightward; - escaped_copy(outbuf, *pp->cgroup, OUTBUF_SIZE, &rightward); + escaped_copy(outbuf, pp->cgname, OUTBUF_SIZE, &rightward); return max_rightward-rightward; } -static int pr_cgname(char *restrict const outbuf,const proc_t *restrict const pp) { +static int pr_cgroup(char *restrict const outbuf,const proc_t *restrict const pp) { int rightward = max_rightward; - int i; - char *name; - - if ((name = strstr(*pp->cgroup, ":name=")) != NULL) { - name += 6; - if (name != '\0') { - escape_str(outbuf, name, OUTBUF_SIZE, &rightward); - return max_rightward - rightward; - } - } - /* fallback: use full cgroup for name */ - return pr_cgroup(outbuf, pp); + + escaped_copy(outbuf, *pp->cgroup, OUTBUF_SIZE, &rightward); + return max_rightward-rightward; } /* Non-standard, from SunOS 5 */ diff --git a/top/top.1 b/top/top.1 index 310a4ede..23caaa2e 100644 --- a/top/top.1 +++ b/top/top.1 @@ -82,7 +82,6 @@ top \- display Linux processes .\" ---------------------------------------------------------------------- \*(WE \*(CL - The traditional switches `\-' and whitespace are optional. .\" ---------------------------------------------------------------------- @@ -632,7 +631,16 @@ A task's currently resident share of available \*(MP. \*(XX. .TP 4 - 3.\fB CGROUPS \*(Em Control Groups \fR + 3.\fB CGNAME \*(Em Control Group Name \fR +The name of the control group to which a process belongs, +or `\-' if not applicable for that process. + +This will typically be the last entry in the full list of control +groups as shown under the next heading (CGROUPS). +And as is true there, this field is also variable width. + +.TP 4 + 4.\fB CGROUPS \*(Em Control Groups \fR The names of the control group(s) to which a process belongs, or `\-' if not applicable for that process. @@ -653,14 +661,14 @@ Even so, such variable width fields could still suffer truncation. any truncated data. .TP 4 - 4.\fB CODE \*(Em Code Size (KiB) \fR + 5.\fB CODE \*(Em Code Size (KiB) \fR The amount of \*(MP currently devoted to executable code, also known as the Text Resident Set size or TRS. \*(XX. .TP 4 - 5.\fB COMMAND \*(Em Command\fB Name\fR or Command\fB Line \fR + 6.\fB COMMAND \*(Em Command\fB Name\fR or Command\fB Line \fR Display the command line used to start a task or the name of the associated program. You toggle between command\fI line\fR and\fI name\fR with `c', which is both @@ -684,7 +692,7 @@ displayed (the `c' \*(CI.) any truncated data. .TP 4 - 6.\fB DATA \*(Em Data + Stack Size (KiB) \fR + 7.\fB DATA \*(Em Data + Stack Size (KiB) \fR The amount of private memory \fIreserved\fR by a process. It is also known as the Data Resident Set or DRS. Such memory may not yet be mapped to \*(MP (RES) but will always be @@ -693,7 +701,7 @@ included in the \*(MV (VIRT) amount. \*(XX. .TP 4 - 7.\fB ENVIRON \*(Em Environment variables \fR + 8.\fB ENVIRON \*(Em Environment variables \fR Display all of the environment variables, if any, as seen by the respective processes. These variables will be displayed in their raw native order, not the @@ -708,26 +716,26 @@ This is especially true for this field. any truncated data. .TP 4 - 8.\fB Flags \*(Em Task Flags \fR + 9.\fB Flags \*(Em Task Flags \fR This column represents the task's current scheduling flags which are expressed in hexadecimal notation and with zeros suppressed. These flags are officially documented in . .TP 4 - 9.\fB GID \*(Em Group Id \fR +10.\fB GID \*(Em Group Id \fR The\fI effective\fR group ID. .TP 4 -10.\fB GROUP \*(Em Group Name \fR +11.\fB GROUP \*(Em Group Name \fR The\fI effective\fR group name. .TP 4 -11.\fB LXC \*(Em Lxc Container Name \fR +12.\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 -12.\fB NI \*(Em Nice Value \fR +13.\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. @@ -735,19 +743,19 @@ Zero in this field simply means priority will not be adjusted in determining a task's dispatch-ability. .TP 4 -13.\fB OOMa \*(Em Out of Memory Adjustment Factor \fR +14.\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 -14.\fB OOMs \*(Em Out of Memory Score \fR +15.\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 -15.\fB P \*(Em Last used \*(PU (SMP) \fR +16.\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. @@ -756,7 +764,7 @@ processes to change \*(PUs more often (because of the extra demand for \*(Pu time). .TP 4 -16.\fB PGRP \*(Em Process Group Id \fR +17.\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. @@ -766,7 +774,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 -17.\fB PID \*(Em Process Id \fR +18.\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. @@ -777,11 +785,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 -18.\fB PPID \*(Em Parent Process Id \fR +19.\fB PPID \*(Em Parent Process Id \fR The process ID (pid) of a task's parent. .TP 4 -19.\fB PR \*(Em Priority \fR +20.\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. @@ -791,7 +799,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 -20.\fB RES \*(Em Resident Memory Size (KiB) \fR +21.\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. @@ -806,35 +814,35 @@ modified, act as a dedicated \*(MS and thus will never impact SWAP. \*(XX. .TP 4 -21.\fB RSan \*(Em Resident Anonymous Memory Size (KiB) \fR +22.\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 -22.\fB RSfd \*(Em Resident File-Backed Memory Size (KiB) \fR +23.\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 -23.\fB RSlk \*(Em Resident Locked Memory Size (KiB) \fR +24.\fB RSlk \*(Em Resident Locked Memory Size (KiB) \fR A subset of resident memory (RES) which cannot be swapped out. .TP 4 -24.\fB RSsh \*(Em Resident Shared Memory Size (KiB) \fR +25.\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 -25.\fB RUID \*(Em Real User Id \fR +26.\fB RUID \*(Em Real User Id \fR The\fI real\fR user ID. .TP 4 -26.\fB RUSER \*(Em Real User Name \fR +27.\fB RUSER \*(Em Real User Name \fR The\fI real\fR user name. .TP 4 -27.\fB S \*(Em Process Status \fR +28.\fB S \*(Em Process Status \fR The status of the task which can be one of: \fBD\fR = uninterruptible sleep \fBR\fR = running @@ -849,7 +857,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 -28.\fB SHR \*(Em Shared Memory Size (KiB) \fR +29.\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 @@ -858,7 +866,7 @@ program images and shared libraries. \*(XX. .TP 4 -29.\fB SID \*(Em Session Id \fR +30.\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. @@ -867,11 +875,11 @@ member of the session, called the session leader, which is usually the login shell. .TP 4 -30.\fB SUID \*(Em Saved User Id \fR +31.\fB SUID \*(Em Saved User Id \fR The\fI saved\fR user ID. .TP 4 -31.\fB SUPGIDS \*(Em Supplementary Group IDs \fR +32.\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. @@ -884,7 +892,7 @@ Even so, such variable width fields could still suffer truncation. any truncated data. .TP 4 -32.\fB SUPGRPS \*(Em Supplementary Group Names \fR +33.\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. @@ -897,24 +905,24 @@ Even so, such variable width fields could still suffer truncation. any truncated data. .TP 4 -33.\fB SUSER \*(Em Saved User Name \fR +34.\fB SUSER \*(Em Saved User Name \fR The\fI saved\fR user name. .TP 4 -34.\fB SWAP \*(Em Swapped Size (KiB) \fR +35.\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 -35.\fB TGID \*(Em Thread Group Id \fR +36.\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 -36.\fB TIME \*(Em \*(PU Time \fR +37.\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. @@ -922,19 +930,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 -37.\fB TIME+ \*(Em \*(PU Time, hundredths \fR +38.\fB TIME+ \*(Em \*(PU Time, hundredths \fR The same as TIME, but reflecting more granularity through hundredths of a second. .TP 4 -38.\fB TPGID \*(Em Tty Process Group Id \fR +39.\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 -39.\fB TTY \*(Em Controlling Tty \fR +40.\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. @@ -942,22 +950,22 @@ However, a task need not be associated with a terminal, in which case you'll see `?' displayed. .TP 4 -40.\fB UID \*(Em User Id \fR +41.\fB UID \*(Em User Id \fR The\fI effective\fR user ID of the task's owner. .TP 4 -41.\fB USED \*(Em Memory in Use (KiB) \fR +42.\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 -42.\fB USER \*(Em User Name \fR +43.\fB USER \*(Em User Name \fR The\fI effective\fR user name of the task's owner. .TP 4 -43.\fB VIRT \*(Em Virtual Memory Size (KiB) \fR +44.\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. @@ -965,20 +973,20 @@ swapped out and pages that have been mapped but not used. \*(XX. .TP 4 -44.\fB WCHAN \*(Em Sleeping in Function \fR +45.\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 -45.\fB nDRT \*(Em Dirty Pages Count \fR +46.\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 memory location can be used for some other virtual page. .TP 4 -46.\fB nMaj \*(Em Major Page Fault Count \fR +47.\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 +994,7 @@ A major page fault is when \*(AS access is involved in making that page available. .TP 4 -47.\fB nMin \*(Em Minor Page Fault count \fR +48.\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. @@ -998,50 +1006,49 @@ page available. The number of threads associated with a process. .TP 4 -49.\fB nsIPC \*(Em IPC namespace \fR +50.\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 -50.\fB nsMNT \*(Em MNT namespace \fR +51.\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 -51.\fB nsNET \*(Em NET namespace \fR +52.\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 -52.\fB nsPID \*(Em PID namespace \fR +53.\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 -53.\fB nsUSER \*(Em USER namespace \fR +54.\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 -54.\fB nsUTS \*(Em UTS namespace \fR +55.\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 -55.\fB vMj \*(Em Major Page Fault Count Delta\fR +56.\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 -56.\fB vMn \*(Em Minor Page Fault Count Delta\fR +57.\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). - .\" ...................................................................... .SS 3b. MANAGING Fields .\" ---------------------------------------------------------------------- @@ -2321,7 +2328,6 @@ The entries in the \*(We rcfile would have a number for the `.name' element and the `help' entry would identify a shell script you've written explaining what those numbered selections actually mean. In that way, many more choices can be made visible. - .PP .\" ---------------------------------------------------------------------- diff --git a/top/top.c b/top/top.c index c7515bd6..484bc947 100644 --- a/top/top.c +++ b/top/top.c @@ -252,6 +252,7 @@ static const char Graph_bars[] = "|||||||||||||||||||||||||||||||||||||||||||||| * routine may serve more than one column. */ +SCB_STRS(CGN, cgname) SCB_STRS(CGR, cgroup[0]) SCB_STRV(CMD, Frame_cmdlin, cmdline, cmd) SCB_NUM1(COD, trs) @@ -1789,13 +1790,14 @@ static FLD_t Fieldstab[] = { { 6, SK_Kb, A_right, SF(RZA), L_status }, { 6, SK_Kb, A_right, SF(RZF), L_status }, { 6, SK_Kb, A_right, SF(RZL), L_status }, - { 6, SK_Kb, A_right, SF(RZS), L_status } + { 6, SK_Kb, A_right, SF(RZS), L_status }, #else { 4, SK_Kb, A_right, SF(RZA), L_status }, { 4, SK_Kb, A_right, SF(RZF), L_status }, { 4, SK_Kb, A_right, SF(RZL), L_status }, - { 4, SK_Kb, A_right, SF(RZS), L_status } + { 4, SK_Kb, A_right, SF(RZS), L_status }, #endif + { -1, -1, A_left, SF(CGN), L_CGROUP } #undef SF #undef A_left #undef A_right @@ -5337,6 +5339,9 @@ static const char *task_show (const WIN_t *q, const proc_t *p) { } break; #endif + case EU_CGN: + makeVAR(p->cgname); + break; case EU_CGR: makeVAR(p->cgroup[0]); break; diff --git a/top/top.h b/top/top.h index c95688e0..a53bf66c 100644 --- a/top/top.h +++ b/top/top.h @@ -204,6 +204,7 @@ enum pflag { EU_NS1, EU_NS2, EU_NS3, EU_NS4, EU_NS5, EU_NS6, EU_LXC, EU_RZA, EU_RZF, EU_RZL, EU_RZS, + EU_CGN, #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 16d0889f..4413c46c 100644 --- a/top/top_nls.c +++ b/top/top_nls.c @@ -290,6 +290,9 @@ static void build_two_nlstabs (void) { /* Translation Hint: maximum 'RSsh' = 4 */ Head_nlstab[EU_RZS] = _("RSsh"); Desc_nlstab[EU_RZS] = _("RES Shared (KiB)"); +/* Translation Hint: maximum 'CGNAME' = 7 */ + Head_nlstab[EU_CGN] = _("CGNAME"); + Desc_nlstab[EU_CGN] = _("Control Group name"); }