Skip to content

darwin: respect the update_process_names setting - #2141

Open
cabhinaba3 wants to merge 1 commit into
htop-dev:mainfrom
cabhinaba3:darwin-update-process-names
Open

cabhinaba3 wants to merge 1 commit into
htop-dev:mainfrom
cabhinaba3:darwin-update-process-names

Conversation

@cabhinaba3

@cabhinaba3 cabhinaba3 commented Oct 25, 2026 •

Copy link
Copy Markdown

darwin: respect the update_process_names setting

Fixes #915.

On Darwin, "Update process names on every refresh" had no effect. DarwinProcess_setFromKInfoProc() read the command line once.

With the necessary setting on, both are now re-read for processes htop already knows about, as Linux does (LinuxProcessTable_readCmdlineFile() also refreshes the binary). Zombies are skipped, as on Linux: their arguments can no longer be read, and the fallback would shrink the full command line to p_comm.

With the setting off, nothing changes.

Before

htop stays at count=0 while ps shows the process renaming itself every second.

before

After

htop follows the process, matching ps at the same second.

after

Exec and zombie

A process that execs /bin/sleep under the same PID is shown as sleep 60. A zombie keeps its full command line while ps shows <defunct>.

edge-cases

How to test

A process that rewrites its own argv[1] once a second:

#include <stdio.h>
#include <string.h>
#include <unistd.h>

int main(int argc, char** argv) {
   size_t len = strlen(argv[1]);
   for (int i = 0; ; i++) {
      memset(argv[1], ' ', len);
      snprintf(argv[1], len + 1, "count=%d", i);
      sleep(1);
   }
}
clang renamer.c -o renamer
./renamer XXXXXXXXXXXXXXXXXXXX &
./htop -p $(pgrep -n renamer)

Enable the option under F2, Display options:

setting

The Command column should now follow ps -o command= -p <pid>.

Tested

On macOS 26.6.2 (Apple M1)

Note:

With the setting on, the extra reads cost about 9 ms of CPU per refresh with ~530 processes.

Assisted-by: Claude Opus 5.5

"Update process names on every refresh" had no effect on Darwin, because
the command line and executable were only read when a process was first
seen. Re-read both for known processes when the setting is on, as Linux
does, so that renamed and re-exec'd processes are shown correctly.

Zombies are skipped, as on Linux: their arguments can no longer be read,
and the fallback would replace the full command line with p_comm.

Fixes htop-dev#915

Assisted-by: Claude Opus 5.5
Signed-off-by: Abhinaba Chakraborty <abhinabacr4@gmail.com>
Copilot AI balanced review requested due to automatic review settings October 25, 2026 02:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Walkthrough

For existing Darwin processes, DarwinProcess_setFromKInfoProc now refreshes the executable path and command line when updateProcessNames is enabled and the process is not a zombie. The existing CWD-field check remains limited to initial process setup.

Assessment against linked issues:

Objective Addressed Explanation
Process names reflect changes on OSX [#915] ✅

Suggested reviewers: natoscott

Priority: Normal

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Low · up to f0e10

Enabled refreshes may briefly show degraded process names after a read failure; preserve the previous command line.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Names refresh as processes run
Executable paths update too
Command lines follow each change
Zombie processes stay untouched
Darwin keeps the latest view

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 3191d125-bde4-4e82-a15b-ff9d9faa9737
Commits

Reviewing files that changed from the base of the PR and between 394b4a3 and f0e10f3.

Files selected for processing: 1
  • darwin/DarwinProcess.c

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Comment thread darwin/DarwinProcess.c Resolved
@cabhinaba3

Copy link
Copy Markdown
Author

@BenBE, can you have a look when you have some time? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Process names do not change on OSX

2 participants