Conversation
This is very useful since the built-in pager doesn't support horizontal scroll
... to show the processes of the current user / session only
1. remove `--only-current-session` (not useful on POSIX systems) 2. renames `--only-current-user` for `--show-other-users` to match the pattern of `--show-kthread` 3. simplifies code
See `process.rs` for detail
1. over-allocates the buffer of thread list to reduce the chance of truncation 2. uses info from `kinfo_proc` as fallbacks if available 3. skips further syscalls if `pidinfo::<TaskInfo>` fails
Fixes small bugs
…rname,myself,all>`
…ce#972) Consume the second sampling pass lazily and populate every column and the parent maps before advancing to the next process. This avoids retaining one procfs directory handle per process. Add a CLI regression with a synthetic procfs tree and a child-only file descriptor limit, covering threads, tree output, kernel thread filtering and command reads. Fixes dalance#766
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This is a fairly large change set. It started as "Windows: adds external pager support" and grew into a pass over all four platforms: the platforms that had no
WorkDir,Envor--threadsupport now have them, the macOS backend was rewritten to stop using libproc for enumeration and no longer drops system processes, FreeBSD dropped itsbsd-kvmdependency, and a handful of correctness bugs found along the way were fixed.The
Columntrait signature change (see Row keys below) is the one part that touches almost every file, but it is mechanical.What's new
Windows
--threadnow reports thread names set throughSetThreadDescription.[pager] commandis launched as an external pager. The built-in pager is still the default and is what you get whencommandis unset. This is useful because the built-in pager doesn't support horizontal scroll.macOS
sysctl(CTL_KERN, KERN_PROC, KERN_PROC_ALL)/KERN_PROC_UIDinstead of libproc. System processes are no longer dropped silently.Env,FileNameandWorkDircolumns.--threadsupport, and thread states are mapped onto the same state codes as the other platforms.FreeBSD
WorkDircolumn--threadsupport (KERN_PROC_INC_THREAD).All platforms
show_user_onlyin the[display]section, and the--user(-u) option, to list the processes of one user."all"(the default),"myself"— the effective userprocsruns as — a user name, or a uid in decimal. On Windows, which has no uid, anything that is not one of the two keywords is read as a full SID (S-1-5-21-...-1001) or as an account name (DOMAIN\nameincluded).--user(or-u) means"myself". The command line wins over the configuration file, as it does for the other options that have both.Implementation notes
Row keys: threads carry their thread id negated, and pid is now i64
Threads and processes share the same
HashMapin every column, keyed bypid. Adding thread support meant a thread row needed a key that cannot collide with a pid or with a thread of another process, so a thread row is keyed by-tid(thread_key) and the id is read back out (thread_id).row_sort_keygives the ordering: by the id behind the key, with the process before a thread that was handed the same number, so a thread lands next to its process instead of below every process.pidisi64throughout because a macOS thread id is 64 bit and does not fit ini32.The
Columntrait andViewfollow the type change;ProcessInfoBasewas extracted to holdpid/ppid/intervalfor all four platforms, so column code still readsproc.pidand a platform's ownProcessInfokeeps its kernel-specific fields.Dependencies
bsd-kvm/bsd-kvm-sysare gone on FreeBSDEnumeration and the per-process reads go through
libc::sysctlandkinfo_procdirectly. Two reasons, both of which only got worse once threads were in play:bsd_kvm::get_processwrapskvm_getargvandkvm_getenvv, so every process had its arguments and environment read on every call. WithKERN_PROC_INC_THREADadded — where the kernel emits a process once per thread — that became onekvm_getargv/kvm_getenvvpair per thread of every process, all answering for the same process. Going throughsysctlalso means the reads are made only by the columns that need them (Command,Env,WorkDir) rather than by the collector, and are skipped when those columns are not displayed.bsd-kvm-sysgenerates its bindings withbindgenagainst the running system's headers. FreeBSD's headers move, and a binding that comes out wrong takes the whole build with it — I hit exactly that on my machine.None of this is meant as a criticism of the crates:
kvm_*is a userspace wrapper around the samesysctlcalls, and its real strength — reading kernel dumps — is not somethingprocsuses. If you would rather keep them and have the argument and environment reads moved out ofget_processinstead, I'm happy to reopen that.Bug fixes
Gid/Groupon macOS reported the real group. They readpbi_gid(p_rgid), which made them a copy ofGidReal/GroupReal; they now report the effective group, matching the other platforms.procs --tree --thread.Performance (Both are run on real hardware, with default config)
FreeBSD 15.1, amd64
Slightly faster due to fewer syscalls. See Implementation notes
macOS 26.6.2, aarch64
Slightly slower due to adding system processes. With
--user myselfthe performance is almost the sameScreenshots
FreeBSD
macOS
Windows
CI
macOS is split into
macos-15-intel(x86_64) andmacos-latest(aarch64) in both workflows, and theMakefilegainedrelease_mac_x86_64/release_mac_aarch64, withrelease_mackept as the aggregate target.Testing
Verified on real hardware on every platform this touches, including FreeBSD (amd64) and macOS (on both Intel and Apple Silicon). Therefore macOS and FreeBSD are no longer considered experimental.
Disclaimer
I made the high-level design (hence the
--only-current-user->--show-other-users->--userchange). AI did the most coding.