From 94eb472bcb9ce4bb06a4d3d251b74cec67b41055 Mon Sep 17 00:00:00 2001 From: Jay Hemnani <193022578+jayhemnani9910@users.noreply.github.com> Date: Tue, 27 Oct 2026 00:42:17 +0530 Subject: [PATCH] ps: keep a column for a field that has no value yet 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. --- src/uu/ps/src/picker.rs | 3 ++- tests/by-util/test_ps.rs | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/uu/ps/src/picker.rs b/src/uu/ps/src/picker.rs index be0a1c41..58f67940 100644 --- a/src/uu/ps/src/picker.rs +++ b/src/uu/ps/src/picker.rs @@ -50,7 +50,8 @@ pub(crate) fn collect_pickers( "time" | "cputime" => pickers.push(helper(time)), "ucmd" | "comm" => pickers.push(helper(ucmd)), "cmd" | "command" | "args" => pickers.push(helper(cmd)), - _ => {} + // Not implemented yet: keep the column so later values stay under their headers + _ => pickers.push(helper(|_| "-".to_string())), } } diff --git a/tests/by-util/test_ps.rs b/tests/by-util/test_ps.rs index d6bb2531..60e2ef55 100644 --- a/tests/by-util/test_ps.rs +++ b/tests/by-util/test_ps.rs @@ -417,3 +417,23 @@ fn test_combined_selection_criteria() { assert!(pids.contains(&1)); assert!(pids.len() > 1); } + +#[test] +#[cfg(target_os = "linux")] +fn test_unimplemented_field_keeps_columns_aligned() { + // wchan has no value yet; pid must still be printed in its own column + let out = new_ucmd!() + .args(&["-p", "1", "--no-headers", "-o", "wchan,pid"]) + .succeeds() + .stdout_move_str(); + assert_eq!(out.split_whitespace().collect::>(), ["-", "1"]); + + let out = new_ucmd!() + .args(&["-p", "1", "-l"]) + .succeeds() + .stdout_move_str(); + 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); +}