It's time to fix something in ps output....
By MARco Munari <mar.develops allerta.it>
This patch is pubblic domain.


Index: keyword.c
===================================================================
RCS file: /big/mirror/openbsdcvs/cvs/src/bin/ps/keyword.c,v
retrieving revision 1.23
diff -u -b -r1.23 keyword.c
--- keyword.c   14 Sep 2004 23:45:14 -0000      1.23
+++ keyword.c   24 Jan 2006 20:46:22 -0000
@@ -77,9 +77,19 @@
 #define        GID(n1, n2, fn, off)    UID(n1, n2, fn, off)
 
 #define        PIDFMT  "d"
-#define        PIDLEN  5
+
+#ifndef PID_MAX
+/* older version of sys/proc.h hide it in a ifdef _KERNEL directive */
+#define PID_MAX 32565
+#endif
+#define        PIDLEN  (PID_MAX<=99999 ? 5 :\
+                (PID_MAX<=999999 ? 6 :\
+                 (PID_MAX<=9999999 ? 7 :\
+                  (PID_MAX<=99999999 ? 8 :\
+                   (PID_MAX<=999999999 ? 9 : 10))))) /* (inr)log10 */
 #define        PID(n1, n2, fn, off) \
        { n1, n2, NULL, 0, fn, PIDLEN, 0, off, INT32, PIDFMT }
+#define ADDRLEN 8
 
 #define        USERLEN 8
 
@@ -112,7 +122,7 @@
        {"ktrace", "KTRACE", NULL, 0, pvar, 8, 0, POFF(p_traceflag), INT32, "x"},
        /* XXX */
        {"ktracep", "KTRACEP", NULL, 0, pvar, 8, 0, POFF(p_tracep), UINT64, "llx"},
-       {"lim", "LIM", NULL, 0, maxrss, 5},
+       {"lim", "LIM", NULL, 0, maxrss, 6},
        {"login", "LOGIN", NULL, LJUST, logname, MAXLOGNAME},
        {"logname", "", "login"},
        {"lstart", "STARTED", NULL, LJUST|USER, lstarted, 28},
@@ -128,13 +138,13 @@
        {"nswap", "NSWAP", NULL, USER, pvar, 4, 0, POFF(p_uru_nswap), UINT64, "lld"},
        {"nvcsw", "NVCSW", NULL, USER, pvar, 5, 0, POFF(p_uru_nvcsw), UINT64, "lld"},
        /* XXX */
-       {"nwchan", "WCHAN", NULL, 0, pvar, 6, 0, POFF(p_wchan), UINT64, "llx"},
+       {"nwchan", "WCHAN", NULL, 0, pvar, ADDRLEN, 0, POFF(p_wchan), UINT64, "llx"},
        {"oublk", "OUBLK", NULL, USER, pvar, 4, 0, POFF(p_uru_oublock), UINT64, "lld"},
        {"oublock", "", "oublk"},
        /* XXX */
-       {"p_ru", "P_RU", NULL, 0, pvar, 6, 0, POFF(p_ru), UINT64, "llx"},
+       {"p_ru", "P_RU", NULL, 0, pvar, ADDRLEN, 0, POFF(p_ru), UINT64, "llx"},
        /* XXX */
-       {"paddr", "PADDR", NULL, 0, pvar, 6, 0, POFF(p_paddr), UINT64, "llx"},
+       {"paddr", "PADDR", NULL, 0, pvar, ADDRLEN, 0, POFF(p_paddr), UINT64, "llx"},
        {"pagein", "PAGEIN", NULL, USER, pagein, 6},
        {"pcpu", "", "%cpu"},
        {"pending", "", "sig"},
@@ -153,7 +163,7 @@
        {"rsz", "RSZ", NULL, 0, rssize, 4},
        UID("ruid", "RUID", pvar, POFF(p_ruid)),
        {"ruser", "RUSER", NULL, LJUST, runame, USERLEN},
-       {"sess", "SESS", NULL, 0, pvar, 6, 0, POFF(p_sess), UINT64, "llx"},
+       {"sess", "SESS", NULL, 0, pvar, ADDRLEN, 0, POFF(p_sess), UINT64, "llx"},
        {"sig", "PENDING", NULL, 0, pvar, 8, 0, POFF(p_siglist), INT32, "x"},
        {"sigcatch", "CAUGHT", NULL, 0, pvar, 8, 0, POFF(p_sigcatch), UINT32, "x"},
        {"sigignore", "IGNORED",
@@ -169,7 +179,7 @@
        {"tdev", "TDEV", NULL, 0, tdev, 4},
        {"time", "TIME", NULL, USER, cputime, 9},
        PID("tpgid", "TPGID", pvar, POFF(p_tpgid)),
-       {"tsess", "TSESS", NULL, 0, pvar, 6, 0, POFF(p_tsess), UINT64, "llx"},
+       {"tsess", "TSESS", NULL, 0, pvar, ADDRLEN, 0, POFF(p_tsess), UINT64, "llx"},
        {"tsiz", "TSIZ", NULL, 0, tsize, 4},
        {"tt", "TT", NULL, LJUST, tname, 3},
        {"tty", "TTY", NULL, LJUST, longtname, 8},
@@ -180,7 +190,7 @@
        {"usrpri", "", "upr"},
        {"vsize", "", "vsz"},
        {"vsz", "VSZ", NULL, 0, vsize, 5},
-       {"wchan", "WCHAN", NULL, LJUST, wchan, 6},
+       {"wchan", "WCHAN", NULL, LJUST, wchan, ADDRLEN},
        {"xstat", "XSTAT", NULL, 0, pvar, 4, 0, POFF(p_xstat), UINT16, "x"},
        {""},
 };
@@ -196,11 +206,24 @@
        sep = "";
        for (v = var; *(p = v->name); ++v) {
                int len = strlen(p);
+               (void) printf("%s%s", sep, p);
+
+/* an alternative to my drastical dropping is to complicate the work of ps
+ * even more, checking if the tty is a pipe or a dummy terminal (as it was
+ * supposed to be). Anyway the reason of the dropping is to permit
+ *   ps -o `ps -L|sed s/\ /,/g`|less -S
+ *autoOOPS.. the -w switch (is intended to enlarge terminal)
+ *   ps -o `ps -wwL|sed s/\ /,/g`|less -S
+ *
+ * --MARco Munari
+ */
+//#ifdef fmt_is_unknown_command
                if (termwidth && (i += len + 1) > termwidth) {
                        i = len;
                        sep = "\n";
                }
-               (void) printf("%s%s", sep, p);
+               else
+//#endif
                sep = " ";
        }
        (void) printf("\n");
Index: ps.1
===================================================================
RCS file: /big/mirror/openbsdcvs/cvs/src/bin/ps/ps.1,v
retrieving revision 1.54
diff -u -b -r1.54 ps.1
--- ps.1        6 Sep 2005 23:28:23 -0000       1.54
+++ ps.1        24 Jan 2006 20:46:23 -0000
@@ -100,6 +100,8 @@
 Also display information about kernel threads.
 .It Fl L
 List the set of available keywords.
+(if you want a single long text line use also the -w switch repeated, eg.
+ ps -xko `ps -wwL|sed s/\\ /,/g`|less -S   --MARco Munari)
 .It Fl l
 Display information associated with the following keywords:
 uid, pid, ppid, cpu, pri, nice, vsz, rss, wchan, state, tt, time
