diff -ruN /usr/src/usr.bin/top/machine.c.orig usr.bin/top/machine.c --- /usr/src/usr.bin/top/machine.c.orig Wed May 18 21:42:51 2005 +++ usr.bin/top/machine.c Sat Jun 3 12:33:30 2006 @@ -105,20 +105,20 @@ "%5d %-*.*s %6ld %6ld %6ld %6ld %6ld %6ld %6.2f%% %.*s" static char smp_header_thr[] = - " PID %-*.*s THR PRI NICE SIZE RES STATE C TIME %6s COMMAND"; + " PID%s %-*.*s THR PRI NICE SIZE RES STATE C TIME %6s COMMAND"; static char smp_header[] = - " PID %-*.*s " "PRI NICE SIZE RES STATE C TIME %6s COMMAND"; + " PID%s %-*.*s " "PRI NICE SIZE RES STATE C TIME %6s COMMAND"; #define smp_Proc_format \ - "%5d %-*.*s %s%3d %4d%7s %6s %-6.6s %1x%7s %5.2f%% %.*s" + "%5d%s %-*.*s %s%3d %4d%7s %6s %-6.6s %1x%7s %5.2f%% %.*s" static char up_header_thr[] = - " PID %-*.*s THR PRI NICE SIZE RES STATE TIME %6s COMMAND"; + " PID%s %-*.*s THR PRI NICE SIZE RES STATE TIME %6s COMMAND"; static char up_header[] = - " PID %-*.*s " "PRI NICE SIZE RES STATE TIME %6s COMMAND"; + " PID%s %-*.*s " "PRI NICE SIZE RES STATE TIME %6s COMMAND"; #define up_Proc_format \ - "%5d %-*.*s %s%3d %4d%7s %6s %-6.6s%.0d%7s %5.2f%% %.*s" + "%5d%s %-*.*s %s%3d %4d%7s %6s %-6.6s%.0d%7s %5.2f%% %.*s" /* process state names for the "STATE" column of the display */ @@ -218,7 +218,8 @@ */ char *ordernames[] = { "cpu", "size", "res", "time", "pri", "threads", - "total", "read", "write", "fault", "vcsw", "ivcsw", NULL + "total", "read", "write", "fault", "vcsw", "ivcsw", + "jid", NULL }; #endif @@ -299,6 +300,7 @@ (ps.thread ? smp_header : smp_header_thr) : (ps.thread ? up_header : up_header_thr); snprintf(Header, sizeof(Header), prehead, + ps.jail ? " JID" : "", namelength, namelength, uname_field, ps.wcpu ? "WCPU" : "CPU"); break; @@ -657,7 +659,7 @@ int state; struct rusage ru, *rup; long p_tot, s_tot; - char *proc_fmt, thr_buf[6]; + char *proc_fmt, thr_buf[6], jid_buf[6]; /* find and remember the next proc structure */ hp = (struct handle *)handle; @@ -758,8 +760,15 @@ snprintf(thr_buf, sizeof(thr_buf), "%*d ", sizeof(thr_buf) - 2, pp->ki_numthreads); + if (ps.jail == 0) + jid_buf[0] = '\0'; + else + snprintf(jid_buf, sizeof(jid_buf), " %*d", + sizeof(jid_buf) - 3, pp->ki_jid); + sprintf(fmt, proc_fmt, pp->ki_pid, + jid_buf, namelength, namelength, (*get_userid)(pp->ki_ruid), thr_buf, @@ -891,6 +900,12 @@ return (diff > 0 ? 1 : -1); \ } while (0) +#define ORDERKEY_JID(a, b) do { \ + int diff = (int)(b)->ki_jid - (int)(a)->ki_jid; \ + if (diff != 0) \ + return (diff > 0 ? 1 : -1); \ +} while (0) + /* compare_cpu - the comparison function for sorting by cpu percentage */ int @@ -918,6 +933,8 @@ int compare_size(), compare_res(), compare_time(), compare_prio(), compare_threads(); /* io compare routines */ int compare_iototal(), compare_ioread(), compare_iowrite(), compare_iofault(), compare_vcsw(), compare_ivcsw(); +/* jail id compare routine */ +int compare_jid(); int (*compares[])() = { compare_cpu, @@ -932,6 +949,7 @@ compare_iofault, compare_vcsw, compare_ivcsw, + compare_jid, NULL }; @@ -1015,6 +1033,24 @@ struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2; ORDERKEY_THREADS(p1, p2); + ORDERKEY_PCTCPU(p1, p2); + ORDERKEY_CPTICKS(p1, p2); + ORDERKEY_STATE(p1, p2); + ORDERKEY_PRIO(p1, p2); + ORDERKEY_RSSIZE(p1, p2); + ORDERKEY_MEM(p1, p2); + + return (0); +} + +/* compare_jid - the comparison function for sorting by jid */ +int +compare_jid(void *arg1, void *arg2) +{ + struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1; + struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2; + + ORDERKEY_JID(p1, p2); ORDERKEY_PCTCPU(p1, p2); ORDERKEY_CPTICKS(p1, p2); ORDERKEY_STATE(p1, p2); diff -ruN /usr/src/contrib/top/machine.h.orig contrib/top/machine.h --- /usr/src/contrib/top/machine.h.orig Wed May 18 21:30:08 2005 +++ contrib/top/machine.h Sat Jun 3 12:25:15 2006 @@ -62,6 +62,7 @@ int thread; /* show threads */ int uid; /* only this uid (unless uid == -1) */ int wcpu; /* show weighted cpu */ + int jail; /* show jail id */ char *command; /* only this command (unless == NULL) */ }; diff -ruN /usr/src/contrib/top/top.c.orig contrib/top/top.c --- /usr/src/contrib/top/top.c.orig Sun Apr 30 14:06:33 2006 +++ contrib/top/top.c Sat Jun 3 12:38:45 2006 @@ -193,9 +193,9 @@ fd_set readfds; #ifdef ORDER - static char command_chars[] = "\f qh?en#sdkriIutHmSCo"; + static char command_chars[] = "\f qh?en#sdkriIutHmSCoj"; #else - static char command_chars[] = "\f qh?en#sdkriIutHmSC"; + static char command_chars[] = "\f qh?en#sdkriIutHmSCj"; #endif /* these defines enumerate the "strchr"s of the commands in command_chars */ #define CMD_redraw 0 @@ -222,6 +222,7 @@ #ifdef ORDER #define CMD_order 20 #endif +#define CMD_jidtog 21 /* set the buffer for stdout */ #ifdef DEBUG @@ -252,6 +253,7 @@ ps.uid = -1; ps.thread = No; ps.wcpu = 1; + ps.jail = No; ps.command = NULL; /* get preset options from the environment */ @@ -277,7 +279,7 @@ optind = 1; } - while ((i = getopt(ac, av, "CSIHbinquvs:d:U:m:o:t")) != EOF) + while ((i = getopt(ac, av, "CSIHbijnquvs:d:U:m:o:t")) != EOF) { switch(i) { @@ -394,6 +396,10 @@ ps.thread = !ps.thread; break; + case 'j': + ps.jail = !ps.jail; + break; + default: fprintf(stderr, "Top version %s\n" @@ -1044,6 +1050,15 @@ } break; #endif + case CMD_jidtog: + ps.jail = !ps.jail; + new_message(MT_standout | MT_delayed, + " %sisplaying jail id.", + ps.jail ? "D" : "Not d"); + header_text = format_header(uname_field); + reset_display(); + putchar('\r'); + break; default: new_message(MT_standout, " BAD CASE IN SWITCH!");