From nobody Sun Nov 15 08:15:09 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jS3hF636wz6ygCW for ; Sun, 15 Nov 2026 08:15:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jS3hF4CRMz3NCZ for ; Sun, 15 Nov 2026 08:15:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794730509; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZxckiKLAFUWU5WsIqpTSnNfy2Kbd/blmHJzijND8j+k=; b=hH5Boq6y+Y6NfuK826G17qTXbbS/hT9RsZCKVrTmUa3uu2WTWx7ZcJb+86+CDNUQR+GfOL d89oE68LV7lfXWEpll4R9YS3AMsNwggUGEAPtfIW0frvHo0K85DTnpg7lPSzFO9gnra/7/ 0sB1w+vBVxvkTWv1Dqw5lyosMoYecgPF3Iq5zOzLXaT+leNwc+q6M25vZ/fvlREXFSggLa ztNctvFOOz6OWKNNaM5VAVn0BimqRjqc8JHPR2Vmr+TDeMm6LkVxtip0DxlWikeWtTFWaA v0c3K0clrbIgxgzfKAo7LXF3WRYGcVetTap5UXlxHeMpbuXVA0NG2N/WpYJ8/Q== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794730509; b=KlasOUEXOwe8QEzbD16LlOJAu/62MD1q6OZeukoh7WdVBVBDK928pVxzmq36BK89fRBaZq 7E3WUCJ8C7R6rmHXQEx1eQEPoRjSaDc1gMXr1wjURbDDu7ggorcYVFrbkegI0t/fknheMO 6fSpR3PUN7+a13N8P7Zdd1QB/XEDWNPrqfDsbsYBFJRdQM1Vo10lG9YAwGUgpXqRT8C9MG kt5zm5tCIG+EEwe0Ux4370ceC9rKSDRLin3RJaKdZpox6iS1JG9OVgbfzoIZekE9Tef8XT K01nXJeFi9D1yE8XiHRjnAvYywDgSbWnwX07e5oVz9jVbSf2SVZEqELoVNAtgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794730509; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZxckiKLAFUWU5WsIqpTSnNfy2Kbd/blmHJzijND8j+k=; b=kkOdlmPEZu2nMX/6mhqTEYKk2dtdfzsu2doorrA1Qo4d86ZubkxX22PvQgEDq4F/anDIyR Zdo512qFt9bDxNT/DNy0r0bOKmhMYQyI12epDL/pBtpjsau4NbZXgqJp7/ThoAFmovxKjB SJPpQn1u3xfK5v0wtISD7y0rPpPw9ZV+nHMDGjPAMXvhcz23EURt8tOaFAgcCNG5Ey6hiz zrPzh/cn20M82+PLH8smmrqrWpO85c/qMs0WWlZfCVnVe//vQcqhNKzTgcX/GpEUtZq2es 4H3whL+0pZZLI4KPi5COiI47IfcqsHR59Cgdia0Ic5JWcYrS0qwPCJQBv3tDHw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jS3hF3bWfzyr3 for ; Sun, 15 Nov 2026 08:15:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1143d by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sun, 15 Nov 2026 08:15:09 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Roman Bogorodskiy Subject: git: 3dcd4a2fd6b8 - main - top: implement pid highlighting List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: novel X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 3dcd4a2fd6b84fe962897f3c07e684ce166798a4 Auto-Submitted: auto-generated Date: Sun, 15 Nov 2026 08:15:09 +0000 Message-Id: <6af96a0d.1143d.25b82123@gitrepo.freebsd.org> The branch main has been updated by novel: URL: https://cgit.FreeBSD.org/src/commit/?id=3dcd4a2fd6b84fe962897f3c07e684ce166798a4 commit 3dcd4a2fd6b84fe962897f3c07e684ce166798a4 Author: Roman Bogorodskiy AuthorDate: 2026-11-01 07:28:37 +0000 Commit: Roman Bogorodskiy CommitDate: 2026-11-15 08:14:22 +0000 top: implement pid highlighting Implement PID highlighting. This can be activated by pressing 'L' and entering a PID to highlight. Highlighting can be cleared by entering '+' as a PID to highlight. This feature is inspired by the OpenBSD top, which uses 'P' key for that. We have to use 'L' because 'P' is already used for toggling per-CPU statistics. Reviewed by: kib Obtained from: OpenBSD (partially) MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D61090 --- usr.bin/top/commands.c | 2 +- usr.bin/top/commands.h | 1 + usr.bin/top/display.c | 44 ++++++++++++++++++++++++++++++++++---- usr.bin/top/display.h | 4 ++-- usr.bin/top/machine.c | 5 ++++- usr.bin/top/machine.h | 4 ++-- usr.bin/top/top.1 | 9 +++++++- usr.bin/top/top.c | 58 ++++++++++++++++++++++++++++++++++++++++---------- 8 files changed, 105 insertions(+), 22 deletions(-) diff --git a/usr.bin/top/commands.c b/usr.bin/top/commands.c index 3fa63459f2e1..e4e71862c1ad 100644 --- a/usr.bin/top/commands.c +++ b/usr.bin/top/commands.c @@ -65,6 +65,7 @@ const struct command all_commands[] = {'J', "display processes for only one jail (+ selects all jails)", false, CMD_jail}, {'j', "toggle the display of jail ID", false, CMD_jidtog}, {'k', "kill processes; send a signal to a list of processes", false, CMD_kill}, + {'L', "highlight one process (+ clears highlighting)", false, CMD_hl}, {'m', "toggle the display between 'cpu' and 'io' modes", false, CMD_viewtog}, {'n', "change number of processes to display", false, CMD_number}, {'#', NULL, false, CMD_number}, @@ -515,4 +516,3 @@ renice_procs(char *str) /* return appropriate error string */ return(err_string()); } - diff --git a/usr.bin/top/commands.h b/usr.bin/top/commands.h index 63ed2f9b6471..25ac80c6cd6a 100644 --- a/usr.bin/top/commands.h +++ b/usr.bin/top/commands.h @@ -23,6 +23,7 @@ enum cmd_id { CMD_quit, CMD_help, CMD_grep, + CMD_hl, CMD_errors, CMD_number, CMD_delay, diff --git a/usr.bin/top/display.c b/usr.bin/top/display.c index b6cde0e63aa7..99dbefede237 100644 --- a/usr.bin/top/display.c +++ b/usr.bin/top/display.c @@ -64,6 +64,7 @@ static int lastline = 0; /* buffer of proc information lines for display updating */ static char *screenbuf = NULL; +static bool *screenhl = NULL; static const char * const *procstate_names; static const char * const *cpustate_names; @@ -132,6 +133,8 @@ display_resize(void) { free(screenbuf); } + free(screenhl); + screenhl = NULL; /* calculate the current dimensions */ /* if operating in "dumb" mode, we only need one line */ @@ -147,6 +150,12 @@ display_resize(void) /* oops! */ return(-1); } + screenhl = calloc(lines, sizeof(*screenhl)); + if (screenhl == NULL) { + free(screenbuf); + screenbuf = NULL; + return (-1); + } /* return number of lines available */ /* for dumb terminals, pretend like we can show any amount */ @@ -817,10 +826,11 @@ u_header(const char *text __unused) * *_process(line, thisline) - print one process line * * Assumptions: lastline is consistent + * u_process(): smart_terminal is true */ void -i_process(int line, char *thisline) +i_process(int line, char *thisline, bool hl) { char *p; char *base; @@ -840,11 +850,16 @@ i_process(int line, char *thisline) } /* write the line out */ - fputs(thisline, stdout); + if (hl) + top_standout(thisline); + else + fputs(thisline, stdout); /* copy it in to our buffer */ base = smart_terminal ? screenbuf + lineindex(line) : screenbuf; p = stpcpy(base, thisline); + if (smart_terminal) + screenhl[line] = hl; /* zero fill the rest of it */ if (p - base < screen_width) @@ -854,7 +869,7 @@ i_process(int line, char *thisline) } void -u_process(int line, char *newline) +u_process(int line, char *newline, bool hl) { char *optr; int screen_line = line + Header_lines; @@ -887,7 +902,10 @@ u_process(int line, char *newline) } /* now write the line */ - fputs(newline, stdout); + if (hl) + top_standout(newline); + else + fputs(newline, stdout); /* copy it in to the buffer */ optr = stpcpy(bufferline, newline); @@ -897,6 +915,24 @@ u_process(int line, char *newline) { memset(optr, 0, screen_width - (optr - bufferline)); } + screenhl[line] = hl; + } else if (hl || screenhl[line] != hl) { + int oldlen; + + /* line_update() cannot change or preserve standout attributes */ + oldlen = strlen(bufferline); + Move_to(0, screen_line); + lastline = screen_line; + if (hl) + top_standout(newline); + else + fputs(newline, stdout); + if (len < oldlen) + (void)clear_eol(oldlen - len); + optr = stpcpy(bufferline, newline); + if (optr - bufferline < screen_width) + memset(optr, 0, screen_width - (optr - bufferline)); + screenhl[line] = hl; } else { diff --git a/usr.bin/top/display.h b/usr.bin/top/display.h index 6e930f5ae6eb..b9764bd8ae89 100644 --- a/usr.bin/top/display.h +++ b/usr.bin/top/display.h @@ -19,7 +19,7 @@ void i_cpustates(int *states); void i_loadave(int mpid, double *avenrun); void i_memory(int *stats); void i_message(void); -void i_process(int line, char *thisline); +void i_process(int line, char *thisline, bool hl); void i_procstates(int total, int *brkdn); void i_swap(int *stats); void i_timeofday(time_t *tod); @@ -35,7 +35,7 @@ void u_header(const char *text); void u_loadave(int mpid, double *avenrun); void u_memory(int *stats); void u_message(void); -void u_process(int line, char *newline); +void u_process(int line, char *newline, bool hl); void u_procstates(int total, int *brkdn); void u_swap(int *stats); void z_cpustates(void); diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c index 1f70ee9281e8..3e43b407a9df 100644 --- a/usr.bin/top/machine.c +++ b/usr.bin/top/machine.c @@ -1042,7 +1042,8 @@ cmd_matches(struct kinfo_proc *proc, const char *term) } char * -format_next_process(struct handle * xhandle, char *(*get_userid)(int), int flags) +format_next_process(struct handle *xhandle, char *(*get_userid)(int), int flags, + pid_t *pid) { struct kinfo_proc *pp; const struct kinfo_proc *oldp; @@ -1067,6 +1068,8 @@ format_next_process(struct handle * xhandle, char *(*get_userid)(int), int flags pp = *(xhandle->next_proc++); xhandle->remaining--; + *pid = pp->ki_pid; + /* get the process's command name */ if ((pp->ki_flag & P_INMEM) == 0) { /* diff --git a/usr.bin/top/machine.h b/usr.bin/top/machine.h index b4f2f1a8bd50..cc038aeac407 100644 --- a/usr.bin/top/machine.h +++ b/usr.bin/top/machine.h @@ -82,8 +82,8 @@ struct process_select struct handle; char *format_header(const char *uname_field); -char *format_next_process(struct handle* handle, char *(*get_userid)(int), - int flags); +char *format_next_process(struct handle *handle, char *(*get_userid)(int), + int flags, pid_t *pid); void toggle_pcpustats(void); void get_system_info(struct system_info *si); int machine_init(struct statics *statics); diff --git a/usr.bin/top/top.1 b/usr.bin/top/top.1 index 6c2597aa1334..b22442c4e078 100644 --- a/usr.bin/top/top.1 +++ b/usr.bin/top/top.1 @@ -1,4 +1,4 @@ -.Dd November 11, 2026 +.Dd November 15, 2026 .Dt TOP 1 .Os .Sh NAME @@ -318,6 +318,13 @@ Send a signal to a list of processes. This acts similarly to the command .Xr kill 1 . +.It Ic L +Highlight a specific process. +Prompt for +.Ar PID +or +.Ql Ic + +to clear highlighting. .It Ic m Toggle the display between 'cpu' and 'io' modes. .It Ic n No or Ic # diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c index 3ca766250297..a7463e199a22 100644 --- a/usr.bin/top/top.c +++ b/usr.bin/top/top.c @@ -69,6 +69,7 @@ static int max_topn; /* maximum displayable processes */ /* miscellaneous things */ struct process_select ps; pid_t mypid; +static pid_t hlpid = (pid_t)-1; /* pointers to display routines */ static void (*d_loadave)(int mpid, double *avenrun) = i_loadave; @@ -80,7 +81,7 @@ static void (*d_carc)(int *stats) = i_carc; static void (*d_swap)(int *stats) = i_swap; static void (*d_message)(void) = i_message; static void (*d_header)(const char *text) = i_header; -static void (*d_process)(int line, char *thisline) = i_process; +static void (*d_process)(int line, char *thisline, bool hl) = i_process; static void reset_display(void); @@ -163,6 +164,19 @@ rem_uid(int uid) } } +static pid_t +parse_pid(const char *buf) +{ + unsigned long long num; + const char *errstr; + + num = strtonum(buf, 0, INT_MAX, &errstr); + if (errstr != NULL || !find_pid(num)) + return ((pid_t)-1); + + return ((pid_t)num); +} + static int handle_user(char *buf, size_t buflen) { @@ -372,19 +386,13 @@ main(int argc, const char *argv[]) err(1, NULL); break; - case 'p': { - unsigned long long num; - const char *errstr; - - num = strtonum(optarg, 0, INT_MAX, &errstr); - if (errstr != NULL || !find_pid(num)) { + case 'p': + if ((ps.pid = parse_pid(optarg)) == (pid_t)-1) { fprintf(stderr, "%s: unknown pid\n", optarg); exit(1); } - ps.pid = (pid_t)num; ps.system = true; break; - } case 's': { @@ -667,8 +675,12 @@ restart: /* now show the top "n" processes. */ for (i = 0; i < active_procs; i++) { - (*d_process)(i, format_next_process(processes, get_userid, - fmt_flags)); + char *line; + pid_t pid; + + line = format_next_process(processes, get_userid, + fmt_flags, &pid); + (*d_process)(i, line, pid == hlpid); } } else @@ -922,6 +934,30 @@ restart: clear_message(); break; + case CMD_hl: /* highlight PID */ + new_message(MT_standout, + "Process ID to highlight: "); + if (readline(tempbuf1, sizeof(tempbuf1), + false) > 0) { + pid_t pid; + + if (tempbuf1[0] == '+' && + tempbuf1[1] == '\0') { + hlpid = (pid_t)-1; + } else if ((pid = parse_pid(tempbuf1)) == + (pid_t)-1) { + new_message(MT_standout, + " %s: unknown pid", + tempbuf1); + no_command = true; + } else + hlpid = pid; + if (!no_command) + clear_message(); + } else + clear_message(); + break; + case CMD_displays: /* change display count */ new_message(MT_standout, "Displays to show (currently %s): ",