Skip to content

proc: add cwd to process detail view#1546

Open
amaanq wants to merge 1 commit intoaristocratos:mainfrom
amaanq:proc-cwd-detail
Open

proc: add cwd to process detail view#1546
amaanq wants to merge 1 commit intoaristocratos:mainfrom
amaanq:proc-cwd-detail

Conversation

@amaanq
Copy link
Copy Markdown

@amaanq amaanq commented Feb 18, 2026

The process detail panel now shows the working directory above the command line. On Linux this reads the /proc/[pid]/cwd symlink, on macOS it uses proc_pidinfo with PROC_PIDVNODEPATHINFO, and on FreeBSD/NetBSD it uses sysctl with KERN_PROC_CWD. OpenBSD doesn't expose other processes' cwd so it shows "(unavailable)" there.

The CMD display goes from 3 lines to 2 to make room, which means longer commands truncate a line sooner.

The process detail panel now shows the working directory above the
command line. On Linux this reads the `/proc/[pid]/cwd` symlink, on
macOS it uses `proc_pidinfo` with `PROC_PIDVNODEPATHINFO`, and on
FreeBSD/NetBSD it uses `sysctl` with `KERN_PROC_CWD`. OpenBSD doesn't
expose other processes' cwd so it shows "(unavailable)" there.

The CMD display goes from 3 lines to 2 to make room, which means
longer commands truncate a line sooner.
Copy link
Copy Markdown
Collaborator

@deckstose deckstose left a comment

Choose a reason for hiding this comment

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

Have a few comments on the actual implementation.

Overall I don't like the design. I have several comments on issues in the back of my head where people wanted to see more of the command line in the detailed view, not less, which often doesn't even fit on three lines.

Also the keywords CWD and CMD are hard to distinguish right beneath each other.

I think we can come up with a better solution than this.

if (fs::is_symlink(pid_path / "cwd"))
detailed.cwd = fs::read_symlink(pid_path / "cwd").string();
}
catch (...) {}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add a comment why an exception can be safely ignored.

Comment thread src/btop_draw.cpp
for (int i = 0; const auto& l : {'C', 'M', 'D'})
out += Mv::to(d_y + 5 + i++, d_x + 1) + l;
//? CWD and Command line
out += Mv::to(d_y + 5, d_x + 1) + Theme::c("title") + Fx::b + "CWD" + Fx::ub;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please use fmt::format_to when editing or writing new draw code.

See CONTRIBUTING.md and #535 for more information.

Comment thread src/btop_draw.cpp
//? Command line
for (int i = 0; const auto& l : {'C', 'M', 'D'})
out += Mv::to(d_y + 5 + i++, d_x + 1) + l;
//? CWD and Command line
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

NIT: Although it's done like this everywhere else the question mark in comments doesn't add any value IMO and can be left out.

Comment thread src/btop_shared.hpp
bool skip_smaps{};
proc_info entry;
string elapsed, parent, status, io_read, io_write, memory;
string elapsed, parent, status, io_read, io_write, memory, cwd;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
string elapsed, parent, status, io_read, io_write, memory, cwd;
string elapsed, parent, status, io_read, io_write, memory;
std::string cwd;
Suggested change
string elapsed, parent, status, io_read, io_write, memory, cwd;
string elapsed, parent, status, io_read, io_write, memory;
string cwd;

Please do not add new variables to multi-line declarations.

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.

2 participants