Download raw body.
autoadjust ps columns
Here's a second diff that removes the obsolete RSZ.
It's supposed to be rss + text, but hasn't worked in ages.
Index: extern.h
===================================================================
RCS file: /home/cvs/src/bin/ps/extern.h,v
diff -u -p -r1.24 extern.h
--- extern.h 1 Sep 2022 21:15:54 -0000 1.24
+++ extern.h 26 Apr 2025 16:38:25 -0000
@@ -37,7 +37,7 @@ struct var;
struct varent;
extern fixpt_t ccpu;
-extern int eval, fscale, nlistread, maxslp;
+extern int eval, fscale, nlistread, maxslp, pagesize;
extern u_int mempages;
extern int sumrusage, termwidth, totwidth, kvm_sysctl_only, needheader;
extern VAR var[];
@@ -68,7 +68,6 @@ void printheader(void);
void pvar(const struct pinfo *, VARENT *);
void pnice(const struct pinfo *, VARENT *);
void rgname(const struct pinfo *, VARENT *);
-void rssize(const struct pinfo *, VARENT *);
void runame(const struct pinfo *, VARENT *);
void showkey(void);
void started(const struct pinfo *, VARENT *);
Index: keyword.c
===================================================================
RCS file: /home/cvs/src/bin/ps/keyword.c,v
diff -u -p -r1.54 keyword.c
--- keyword.c 24 Mar 2025 21:43:40 -0000 1.54
+++ keyword.c 26 Apr 2025 16:39:31 -0000
@@ -153,8 +153,6 @@ VAR var[] = {
{"rgroup", "RGROUP", NULL, LJUST, rgname, USERLEN},
{"rlink", "RLINK", NULL, 0, pvar, 8, 0, POFF(p_back), UINT64, "llx"},
{"rss", "RSS", NULL, 0, p_rssize, 6},
- {"rssize", "", "rsz"},
- {"rsz", "RSZ", NULL, 0, rssize, 4},
{"rtable", "RTABLE", NULL, 0, pvar, 0, 0, POFF(p_rtableid), INT32, "d"},
UID("ruid", "RUID", pvar, POFF(p_ruid)),
{"ruser", "RUSER", NULL, LJUST, runame, USERLEN},
Index: print.c
===================================================================
RCS file: /home/cvs/src/bin/ps/print.c,v
diff -u -p -r1.89 print.c
--- print.c 28 Apr 2024 16:43:15 -0000 1.89
+++ print.c 26 Apr 2025 16:37:56 -0000
@@ -239,7 +239,7 @@ logname(const struct pinfo *pi, VARENT *
(void)printf("%-*s", v->width, "-");
}
-#define pgtok(a) (((unsigned long long)(a)*getpagesize())/1024)
+#define pgtok(a) (((unsigned long long)(a)*pagesize)/1024)
void
printstate(const struct pinfo *pi, VARENT *ve)
@@ -625,18 +625,6 @@ vsize(const struct pinfo *pi, VARENT *ve
v = ve->var;
(void)printf("%*llu", v->width,
pgtok(kp->p_vm_dsize + kp->p_vm_ssize + kp->p_vm_tsize));
-}
-
-void
-rssize(const struct pinfo *pi, VARENT *ve)
-{
- const struct kinfo_proc *kp = pi->ki;
- VAR *v;
-
- v = ve->var;
- /* XXX don't have info about shared */
- (void)printf("%*llu", v->width, (kp->p_flag & P_SYSTEM) ? 0 :
- pgtok(kp->p_vm_rssize));
}
void
Index: ps.1
===================================================================
RCS file: /home/cvs/src/bin/ps/ps.1,v
diff -u -p -r1.139 ps.1
--- ps.1 15 Oct 2024 13:49:49 -0000 1.139
+++ ps.1 26 Apr 2025 16:36:14 -0000
@@ -371,10 +371,6 @@ Text name of real group ID.
Reverse link on run queue, or 0.
.It Cm rss
The real memory (resident set) size of the process (in 1024 byte units).
-.It Cm rsz
-Alias:
-.Cm rssize .
-Resident set size + (text size / text use count).
.It Cm rtable
Routing table.
.It Cm ruid
Index: ps.c
===================================================================
RCS file: /home/cvs/src/bin/ps/ps.c,v
diff -u -p -r1.81 ps.c
--- ps.c 18 May 2024 13:08:09 -0000 1.81
+++ ps.c 26 Apr 2025 16:34:58 -0000
@@ -65,6 +65,7 @@ int eval; /* exit value */
int sumrusage; /* -S */
int termwidth; /* width of screen (0 == infinity) */
int totwidth; /* calculated width of requested variables */
+int pagesize;
int needcomm, needenv, neednlist, commandonly;
@@ -72,7 +73,7 @@ enum sort { DEFAULT, SORTMEM, SORTCPU }
static char *kludge_oldps_options(char *);
static int pscomp(const void *, const void *);
-static void scanvars(void);
+static void scanvars(struct kinfo_proc *kp, size_t nentries);
static void forest_sort(struct pinfo *, int);
static void usage(void);
@@ -116,6 +117,7 @@ main(int argc, char *argv[])
termwidth = ws.ws_col - 1;
if (termwidth == 0)
termwidth = 79;
+ pagesize = getpagesize();
if (argc > 1)
argv[1] = kludge_oldps_options(argv[1]);
@@ -325,12 +327,6 @@ main(int argc, char *argv[])
Uflag = 1;
}
- /*
- * scan requested variables, noting what structures are needed,
- * and adjusting header widths as appropriate.
- */
- scanvars();
-
if (neednlist && !nlistread)
(void) donlist();
@@ -364,6 +360,12 @@ main(int argc, char *argv[])
errx(1, "%s", kvm_geterr(kd));
/*
+ * scan requested variables, noting what structures are needed,
+ * and adjusting header widths as appropriate.
+ */
+ scanvars(kp, nentries);
+
+ /*
* print header
*/
printheader();
@@ -404,14 +406,31 @@ main(int argc, char *argv[])
}
static void
-scanvars(void)
+scanvars(struct kinfo_proc *kp, size_t nentries)
{
struct varent *vent;
VAR *v;
int i;
+ int vszbump = 0, rssbump = 0;
+#define pgtok(a) (((unsigned long long)(a)*pagesize)/1024)
+ for (i = 0; i < nentries; i++) {
+ struct kinfo_proc *ki = &kp[i];
+ if (vszbump == 0 && pgtok(ki->p_vm_dsize + ki->p_vm_ssize + ki->p_vm_tsize) >= 100000)
+ vszbump = 1;
+ if (vszbump == 1 && pgtok(ki->p_vm_dsize + ki->p_vm_ssize + ki->p_vm_tsize) >= 1000000)
+ vszbump = 2;
+ if (rssbump == 0 && pgtok(ki->p_vm_rssize) >= 100000)
+ rssbump = 1;
+ if (rssbump == 1 && pgtok(ki->p_vm_rssize) >= 1000000)
+ rssbump = 2;
+ }
for (vent = vhead; vent; vent = vent->next) {
v = vent->var;
+ if (strcmp(v->name, "vsz") == 0)
+ v->width += vszbump;
+ if (strcmp(v->name, "rss") == 0)
+ v->width += rssbump;
i = strlen(v->header);
if (v->width < i)
v->width = i;
autoadjust ps columns