From: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca>
To: Cygwin Patches <cygwin-patches@cygwin.com>
Subject: [PATCH 1/1] fhandler_process.cc(format_process_stat): fix /proc/pid/stat issues
Date: Tue, 10 May 2022 08:44:42 -0600 [thread overview]
Message-ID: <20220510144443.5555-2-Brian.Inglis@SystematicSW.ab.ca> (raw)
In-Reply-To: <20220510144443.5555-1-Brian.Inglis@SystematicSW.ab.ca>
[-- Attachment #1: Type: text/plain, Size: 435 bytes --]
fix tty_nr maj/min bits, vmmaxrss units, and x86 format mismatch:
ctty maj is 31:16, min is 15:0; tty_nr s/b maj 15:8, min 31:20, 7:0;
vmmaxrss s/b bytes not pages;
times all 64 bit - change formats of first two instances from %lu to %U;
realign sprintf formats and variables/values in more logical groups
---
winsup/cygwin/fhandler_process.cc | 33 +++++++++++++++++++------------
1 file changed, 20 insertions(+), 13 deletions(-)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-fhandler_process.cc-format_process_stat-fix-proc-pid-stat-issues.patch --]
[-- Type: text/x-patch; name="0001-fhandler_process.cc-format_process_stat-fix-proc-pid-stat-issues.patch", Size: 2048 bytes --]
diff --git a/winsup/cygwin/fhandler_process.cc b/winsup/cygwin/fhandler_process.cc
index 4c42bc01568d..718945b9a3ff 100644
--- a/winsup/cygwin/fhandler_process.cc
+++ b/winsup/cygwin/fhandler_process.cc
@@ -1092,6 +1092,11 @@ format_process_stat (void *data, char *&destbuf)
vmsize = 0UL, vmrss = 0UL, vmmaxrss = 0UL;
uint64_t utime = 0ULL, stime = 0ULL, start_time = 0ULL;
int nice = 0;
+/* ctty maj is 31:16, min is 15:0; tty_nr s/b maj 15:8, min 31:20, 7:0;
+ maj is 31:16 >> 16 & fff << 8; min is 15:0 >> 8 & ff << 20 | & ff */
+ int tty_nr = (((p->ctty >> 8) & 0xff) << 20)
+ | (((p->ctty >> 16) & 0xfff) << 8)
+ | (p->ctty & 0xff);
if (p->process_state & PID_EXITED)
strcpy (cmd, "<defunct>");
@@ -1171,23 +1176,25 @@ format_process_stat (void *data, char *&destbuf)
else
start_time = (p->start_time - to_time_t (&stodi.BootTime)) * CLOCKS_PER_SEC;
unsigned page_size = wincap.page_size ();
- vmsize = vmc.PagefileUsage;
- vmrss = vmc.WorkingSetSize / page_size;
- vmmaxrss = ql.MaximumWorkingSetSize / page_size;
+ vmsize = vmc.PagefileUsage; /* bytes */
+ vmrss = vmc.WorkingSetSize / page_size; /* pages */
+ vmmaxrss = ql.MaximumWorkingSetSize; /* bytes */
destbuf = (char *) crealloc_abort (destbuf, strlen (cmd) + 320);
return __small_sprintf (destbuf, "%d (%s) %c "
- "%d %d %d %d %d "
- "%u %lu %lu %u %u %lu %lu "
- "%U %U %d %d %d %d "
- "%U %lu "
- "%ld %lu\n",
+ "%d %d %d %d "
+ "%d %u %lu %lu %u %u "
+ "%U %U %U %U "
+ "%d %d %d %d "
+ "%U "
+ "%lu %ld %lu\n",
p->pid, cmd, state,
- p->ppid, p->pgid, p->sid, p->ctty, -1,
- 0, fault_count, fault_count, 0, 0, utime, stime,
- utime, stime, NZERO + nice, nice, 0, 0,
- start_time, vmsize,
- vmrss, vmmaxrss
+ p->ppid, p->pgid, p->sid, tty_nr,
+ -1, 0, fault_count, fault_count, 0, 0,
+ utime, stime, utime, stime,
+ NZERO + nice, nice, 0, 0,
+ start_time,
+ vmsize, vmrss, vmmaxrss
);
}
next prev parent reply other threads:[~2022-05-10 14:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-10 14:44 [PATCH 0/1] " Brian Inglis
2022-05-10 14:44 ` Brian Inglis [this message]
2022-05-11 8:03 ` [PATCH 1/1] " Corinna Vinschen
2022-05-11 14:55 ` [PATCH 0/1] " Mohammad HOQUE
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220510144443.5555-2-Brian.Inglis@SystematicSW.ab.ca \
--to=brian.inglis@systematicsw.ab.ca \
--cc=cygwin-patches@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).