From: mpi Date: Wed, 6 May 2015 07:53:29 +0000 (+0000) Subject: Display thread IDs instead of the name of the process's owner when "-H" X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=4d3d39ea0cb113195a4616a731593e87300ce3bb;p=openbsd Display thread IDs instead of the name of the process's owner when "-H" is used. The rationnal is that when you're looking at threads you're generally already filtereing by PID and this allow you to see which thread is a pig. Written some time ago with mikeb@ ok sthen@, krw@, guenther@ --- diff --git a/usr.bin/top/display.c b/usr.bin/top/display.c index 6797c5f2854..0b4b7f1eba4 100644 --- a/usr.bin/top/display.c +++ b/usr.bin/top/display.c @@ -1,4 +1,4 @@ -/* $OpenBSD: display.c,v 1.48 2014/11/27 14:08:01 espie Exp $ */ +/* $OpenBSD: display.c,v 1.49 2015/05/06 07:53:29 mpi Exp $ */ /* * Top users/processes display for Unix @@ -100,6 +100,7 @@ int y_idlecursor; int y_procs; extern int ncpu; extern int combine_cpus; +extern struct process_select ps; int header_status = Yes; diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c index c973bc96325..5f027d7eb29 100644 --- a/usr.bin/top/machine.c +++ b/usr.bin/top/machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machine.c,v 1.83 2015/01/19 18:01:13 millert Exp $ */ +/* $OpenBSD: machine.c,v 1.84 2015/05/06 07:53:29 mpi Exp $ */ /*- * Copyright (c) 1994 Thorsten Lockert @@ -222,13 +222,19 @@ machine_init(struct statics *statics) } char * -format_header(char *uname_field) +format_header(char *second_field, int show_threads) { + char *field_name, *thread_field = " TID"; char *ptr; + if (show_threads) + field_name = thread_field; + else + field_name = second_field; + ptr = header + UNAME_START; - while (*uname_field != '\0') - *ptr++ = *uname_field++; + while (*field_name != '\0') + *ptr++ = *field_name++; return (header); } @@ -489,13 +495,15 @@ format_comm(struct kinfo_proc *kp) } char * -format_next_process(caddr_t handle, char *(*get_userid)(uid_t), pid_t *pid) +format_next_process(caddr_t handle, char *(*get_userid)(uid_t), pid_t *pid, + int show_threads) { char *p_wait; struct kinfo_proc *pp; struct handle *hp; int cputime; double pct; + char buf[16]; /* find and remember the next proc structure */ hp = (struct handle *) handle; @@ -512,9 +520,13 @@ format_next_process(caddr_t handle, char *(*get_userid)(uid_t), pid_t *pid) else p_wait = "-"; + if (show_threads) + snprintf(buf, sizeof(buf), "%8d", pp->p_tid); + else + snprintf(buf, sizeof(buf), "%s", (*get_userid)(pp->p_ruid)); + /* format this entry */ - snprintf(fmt, sizeof fmt, Proc_format, - pp->p_pid, (*get_userid)(pp->p_ruid), + snprintf(fmt, sizeof(fmt), Proc_format, pp->p_pid, buf, pp->p_priority - PZERO, pp->p_nice - NZERO, format_k(pagetok(PROCSIZE(pp))), format_k(pagetok(pp->p_vm_rssize)), diff --git a/usr.bin/top/machine.h b/usr.bin/top/machine.h index b1eb86ee90b..eeb10deeee5 100644 --- a/usr.bin/top/machine.h +++ b/usr.bin/top/machine.h @@ -1,4 +1,4 @@ -/* $OpenBSD: machine.h,v 1.19 2015/01/19 01:53:18 deraadt Exp $ */ +/* $OpenBSD: machine.h,v 1.20 2015/05/06 07:53:29 mpi Exp $ */ /* * Top users/processes display for Unix @@ -84,12 +84,12 @@ extern int display_init(struct statics *); /* machine.c */ extern int machine_init(struct statics *); -extern char *format_header(char *); +extern char *format_header(char *, int); extern void get_system_info(struct system_info *); extern caddr_t get_process_info(struct system_info *, struct process_select *, int (*) (const void *, const void *)); -extern char *format_next_process(caddr_t, char *(*)(uid_t), pid_t *); +extern char *format_next_process(caddr_t, char *(*)(uid_t), pid_t *, int); extern uid_t proc_owner(pid_t); extern struct kinfo_proc *getprocs(int, int, int *); diff --git a/usr.bin/top/top.1 b/usr.bin/top/top.1 index 77cd7dd7b3b..c13a98b171d 100644 --- a/usr.bin/top/top.1 +++ b/usr.bin/top/top.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: top.1,v 1.65 2015/02/28 21:51:57 bentley Exp $ +.\" $OpenBSD: top.1,v 1.66 2015/05/06 07:53:29 mpi Exp $ .\" .\" Copyright (c) 1997, Jason Downs. All rights reserved. .\" @@ -23,7 +23,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: February 28 2015 $ +.Dd $Mdocdate: May 6 2015 $ .Dt TOP 1 .Os .Sh NAME @@ -402,6 +402,10 @@ The following fields are displayed: The process ID. .It USERNAME The name of the process's owner. +.It TID +The thread ID, used instead of USERNAME if +.Fl H +is specified. .It UID Used instead of USERNAME if .Fl u diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c index 6e1d99ee8d0..aa2f49bfb0d 100644 --- a/usr.bin/top/top.c +++ b/usr.bin/top/top.c @@ -1,4 +1,4 @@ -/* $OpenBSD: top.c,v 1.82 2014/09/17 01:56:54 dlg Exp $ */ +/* $OpenBSD: top.c,v 1.83 2015/05/06 07:53:29 mpi Exp $ */ /* * Top users/processes display for Unix @@ -360,9 +360,6 @@ main(int argc, char *argv[]) /* initialize termcap */ init_termcap(interactive); - /* get the string to use for the process area header */ - header_text = format_header(uname_field); - /* initialize display interface */ max_topn = display_init(&statics); @@ -472,6 +469,9 @@ restart: /* handle message area */ i_message(); + /* get the string to use for the process area header */ + header_text = format_header(uname_field, ps.threads); + /* update the header area */ i_header(header_text); @@ -502,7 +502,7 @@ restart: char * s; s = format_next_process(processes, get_userid, - &pid); + &pid, ps.threads); i_process(i, s, pid == hlpid); } }