Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/uu/ps/src/ps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {

let mut table = Table::new();
table.set_format(*FORMAT_CLEAN);
if !matches.get_flag("no-headers") {
// As in procps-ng, the header line is left out when every header is
// empty, e.g. `ps -o pid= -o comm=`.
let all_headers_empty = code_mapping.iter().all(|(_, header)| header.is_empty());
if !matches.get_flag("no-headers") && !all_headers_empty {
let header = code_mapping
.iter()
.map(|(_, header)| header)
Expand Down
19 changes: 19 additions & 0 deletions tests/by-util/test_ps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,25 @@ fn test_no_headers_flags() {
}
}

#[test]
#[cfg(target_os = "linux")]
fn test_all_empty_headers_print_no_header_line() {
new_ucmd!()
.args(&["-o", "pid=", "-p", "1"])
.succeeds()
.stdout_matches(&Regex::new(r"\A *1 *\n\z").unwrap());
new_ucmd!()
.args(&["-o", "pid=", "-o", "ppid=", "-p", "1"])
.succeeds()
.stdout_matches(&Regex::new(r"\A *1 +0 *\n\z").unwrap());

// One named header keeps the header line.

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.

are you sure procps-ng splits pid=,ppid? i think it takes ",ppid" as the pid header
could you please use -o pid= -o ppid here instead?

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.

Changed to -o pid= -o ppid in cf68181.

For what it's worth, procps-ng 4.0.4 does split it here; both forms print the same:

$ ps --version
ps from procps-ng 4.0.4
$ ps -o pid=,ppid -p $$
           PPID
1256032   38897
$ ps -o pid= -o ppid -p $$
           PPID
1256032   38897

new_ucmd!()
.args(&["-o", "pid=", "-o", "ppid", "-p", "1"])
.succeeds()
.stdout_matches(&Regex::new(r"\A +PPID *\n *1 +0 *\n\z").unwrap());
}

#[test]
#[cfg(target_os = "linux")]
fn test_deselect() {
Expand Down
Loading