Skip to content

ps: keep a column for a field that has no value yet - #824

Open
jayhemnani9910 wants to merge 2 commits into
uutils:mainfrom
jayhemnani9910:ps-keep-columns-aligned
Open

jayhemnani9910 wants to merge 2 commits into
uutils:mainfrom
jayhemnani9910:ps-keep-columns-aligned

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

A format field that ps can't fill yet prints its header but no value, so every value after it moves one column to the left:

$ ps -p 1 -l
 F  S  UID  PID  PPID      C        PRI  NI  ADDR  SZ  WCHAN  TTY  TIME  CMD
 0  1  0    ?    00:00:01  systemd
$ ps -p 1 -o stat,pid,comm
 STAT  PID      COMMAND
 1     systemd

The PID shows under S and the command under PID. collect_pickers skipped any code without a picker (stat, nice, pri, wchan, lstart, etimes, ...), while the header kept it. Such a field now prints -, which procps-ng also uses for a value it can't show:

$ ps -p 1 -l
 F  S  UID  PID  PPID  C  PRI  NI  ADDR  SZ  WCHAN  TTY  TIME      CMD
 -  -  0    1    0     -  -    -   -     -   -      ?    00:00:01  systemd

Filling in those fields is separate work; this only keeps the values under the right headers.

Tests: test_unimplemented_field_keeps_columns_aligned fails without the change. cargo test: 225 passed (224 on main); clippy clean.

A format field without a picker (stat, nice, pri, wchan, lstart...)
printed its header but no value, so every later value moved one
column left: ps -l showed the PID under S and the PPID under UID.
Print - for such a field, the mark procps uses for a missing value.
Copilot AI balanced review requested due to automatic review settings October 27, 2026 06:05

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.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.44444% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 19.96%. Comparing base (67832aa) to head (753ddbb).
⚠️ Report is 27 commits behind head on main.

Files with missing lines Patch % Lines
src/uu/ps/src/picker.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #824      +/-   ##
==========================================
+ Coverage   19.20%   19.96%   +0.76%     
==========================================
  Files          68       68              
  Lines       10156    10298     +142     
  Branches      546      552       +6     
==========================================
+ Hits         1950     2056     +106     
- Misses       8206     8242      +36     
Flag Coverage Δ
macos_latest ?
ubuntu_latest 20.35% <94.44%> (+0.79%) ⬆️
windows_latest 0.02% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread tests/by-util/test_ps.rs Outdated
let mut lines = out.lines();
let headers = lines.next().unwrap().split_whitespace().count();
let values = lines.next().unwrap().split_whitespace().count();
assert_eq!(headers, values);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe also check that the value under PID is 1, not only the count? :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, the test now finds the PID column and checks that its value is 1.

Copilot AI balanced review requested due to automatic review settings November 9, 2026 08:53

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. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

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.

3 participants