proc: add cwd to process detail view#1546
Conversation
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.
There was a problem hiding this comment.
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 (...) {} |
There was a problem hiding this comment.
Please add a comment why an exception can be safely ignored.
| 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; |
There was a problem hiding this comment.
Please use fmt::format_to when editing or writing new draw code.
See CONTRIBUTING.md and #535 for more information.
| //? 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 |
There was a problem hiding this comment.
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.
| 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; |
There was a problem hiding this comment.
| string elapsed, parent, status, io_read, io_write, memory, cwd; | |
| string elapsed, parent, status, io_read, io_write, memory; | |
| std::string cwd; |
| 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.
The process detail panel now shows the working directory above the command line. On Linux this reads the
/proc/[pid]/cwdsymlink, on macOS it usesproc_pidinfowithPROC_PIDVNODEPATHINFO, and on FreeBSD/NetBSD it usessysctlwithKERN_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.