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@
-/* $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
int y_procs;
extern int ncpu;
extern int combine_cpus;
+extern struct process_select ps;
int header_status = Yes;
-/* $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 <tholo@sigmasoft.com>
}
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);
}
}
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;
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)),
-/* $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
/* 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 *);
-.\" $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.
.\"
.\" 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
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
-/* $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
/* 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);
/* 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);
char * s;
s = format_next_process(processes, get_userid,
- &pid);
+ &pid, ps.threads);
i_process(i, s, pid == hlpid);
}
}