93 lines
4.4 KiB
Diff
93 lines
4.4 KiB
Diff
Description: More ps time sorting
|
|
Author: Alfredo Esteban <aedelatorre@gmail.com>
|
|
Bug-Debian: http://bugs.debian.org/508435
|
|
Author: <csmall@debian.org>
|
|
Index: b/ps/output.c
|
|
===================================================================
|
|
--- a/ps/output.c 2009-11-24 20:53:06.000000000 +1100
|
|
+++ b/ps/output.c 2009-11-24 21:00:30.000000000 +1100
|
|
@@ -110,6 +110,20 @@
|
|
return (int)(P->NAME) - (int)(Q->NAME); \
|
|
}
|
|
|
|
+#define cook_time(P) (P->utime + P->stime) / Hertz
|
|
+
|
|
+#define cook_etime(P) seconds_since_boot - (unsigned long)(P->start_time / Hertz)
|
|
+
|
|
+#define CMP_COOKED_TIME(NAME) \
|
|
+static int sr_ ## NAME (const proc_t* P, const proc_t* Q) { \
|
|
+ unsigned long p_time,q_time; \
|
|
+ p_time=cook_ ##NAME (P); \
|
|
+ q_time=cook_ ##NAME (Q); \
|
|
+ if (p_time < q_time) return -1; \
|
|
+ if (p_time > q_time) return 1; \
|
|
+ return 0; \
|
|
+}
|
|
+
|
|
CMP_INT(rtprio)
|
|
CMP_SMALL(sched)
|
|
CMP_INT(cutime)
|
|
@@ -185,6 +199,9 @@
|
|
|
|
CMP_SMALL(state)
|
|
|
|
+CMP_COOKED_TIME(time)
|
|
+CMP_COOKED_TIME(etime)
|
|
+
|
|
/* approximation to: kB of address space that could end up in swap */
|
|
static int sr_swapable(const proc_t* P, const proc_t* Q) {
|
|
unsigned long p_swapable = P->vm_data + P->vm_stack;
|
|
@@ -408,7 +425,7 @@
|
|
unsigned long t;
|
|
unsigned dd,hh,mm,ss;
|
|
char *cp = outbuf;
|
|
- t = seconds_since_boot - (unsigned long)(pp->start_time / Hertz);
|
|
+ t = cook_etime(pp);
|
|
ss = t%60;
|
|
t /= 60;
|
|
mm = t%60;
|
|
@@ -476,7 +493,7 @@
|
|
unsigned long t;
|
|
unsigned dd,hh,mm,ss;
|
|
int c;
|
|
- t = (pp->utime + pp->stime) / Hertz;
|
|
+ t = cook_time(pp);
|
|
ss = t%60;
|
|
t /= 60;
|
|
mm = t%60;
|
|
@@ -1286,7 +1303,7 @@
|
|
{"alarm", "ALARM", pr_alarm, sr_alarm, 5, 0, LNX, AN|RIGHT},
|
|
{"argc", "ARGC", pr_nop, sr_nop, 4, 0, LNX, PO|RIGHT},
|
|
{"args", "COMMAND", pr_args, sr_cmd, 27, ARG, U98, PO|UNLIMITED}, /*command*/
|
|
-{"atime", "TIME", pr_time, sr_nop, 8, 0, SOE, ET|RIGHT}, /*cputime*/ /* was 6 wide */
|
|
+{"atime", "TIME", pr_time, sr_time, 8, 0, SOE, ET|RIGHT}, /*cputime*/ /* was 6 wide */
|
|
{"blocked", "BLOCKED", pr_sigmask, sr_nop, 9, 0, BSD, TO|SIGNAL}, /*sigmask*/
|
|
{"bnd", "BND", pr_nop, sr_nop, 1, 0, AIX, TO|RIGHT},
|
|
{"bsdstart", "START", pr_bsdstart, sr_nop, 6, 0, LNX, ET|RIGHT},
|
|
@@ -1305,7 +1322,7 @@
|
|
{"cp", "CP", pr_cp, sr_pcpu, 3, 0, DEC, ET|RIGHT}, /*cpu*/
|
|
{"cpu", "CPU", pr_nop, sr_nop, 3, 0, BSD, AN|RIGHT}, /* FIXME ... HP-UX wants this as the CPU number for SMP? */
|
|
{"cpuid", "CPUID", pr_psr, sr_nop, 5, 0, BSD, TO|RIGHT}, // OpenBSD: 8 wide!
|
|
-{"cputime", "TIME", pr_time, sr_nop, 8, 0, DEC, ET|RIGHT}, /*time*/
|
|
+{"cputime", "TIME", pr_time, sr_time, 8, 0, DEC, ET|RIGHT}, /*time*/
|
|
{"cstime", "-", pr_nop, sr_cstime, 1, 0, LNX, AN|RIGHT},
|
|
{"ctid", "CTID", pr_nop, sr_nop, 5, 0, SUN, ET|RIGHT}, // resource contracts?
|
|
{"cursig", "CURSIG", pr_nop, sr_nop, 6, 0, DEC, AN|RIGHT},
|
|
@@ -1320,7 +1337,7 @@
|
|
{"end_code", "E_CODE", pr_nop, sr_end_code, 8, 0, LNx, PO|RIGHT},
|
|
{"environ","ENVIRONMENT",pr_nop, sr_nop, 11, ENV, LNx, PO|UNLIMITED},
|
|
{"esp", "ESP", pr_esp, sr_kstk_esp, 8, 0, LNX, TO|RIGHT},
|
|
-{"etime", "ELAPSED", pr_etime, sr_nop, 11, 0, U98, ET|RIGHT}, /* was 7 wide */
|
|
+{"etime", "ELAPSED", pr_etime, sr_etime, 11, 0, U98, ET|RIGHT}, /* was 7 wide */
|
|
{"euid", "EUID", pr_euid, sr_euid, 5, 0, LNX, ET|RIGHT},
|
|
{"euser", "EUSER", pr_euser, sr_euser, 8, USR, LNX, ET|USER},
|
|
{"f", "F", pr_flag, sr_flags, 1, 0, XXX, ET|RIGHT}, /*flags*/
|
|
@@ -1463,7 +1480,7 @@
|
|
{"tdev", "TDEV", pr_nop, sr_nop, 4, 0, XXX, AN|RIGHT},
|
|
{"thcount", "THCNT", pr_nlwp, sr_nlwp, 5, 0, AIX, PO|RIGHT},
|
|
{"tid", "TID", pr_thread, sr_tid, 5, 0, AIX, TO|PIDMAX|RIGHT},
|
|
-{"time", "TIME", pr_time, sr_nop, 8, 0, U98, ET|RIGHT}, /*cputime*/ /* was 6 wide */
|
|
+{"time", "TIME", pr_time, sr_time, 8, 0, U98, ET|RIGHT}, /*cputime*/ /* was 6 wide */
|
|
{"timeout", "TMOUT", pr_nop, sr_nop, 5, 0, LNX, AN|RIGHT}, // 2.0.xx era
|
|
{"tmout", "TMOUT", pr_nop, sr_nop, 5, 0, LNX, AN|RIGHT}, // 2.0.xx era
|
|
{"tname", "TTY", pr_tty8, sr_tty, 8, 0, DEC, PO|LEFT},
|