Skip to content

Commit

Permalink
Fix PID duplication in report
Browse files Browse the repository at this point in the history
When monitoring FDs, merging values from the same program but with different PID was leading
to wrong results
  • Loading branch information
MattBlack85 committed Jan 11, 2022
1 parent 117a854 commit c7e1c8d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "astromonitor"
version = "0.4.0"
version = "0.4.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
13 changes: 3 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn fd_report() {
.expect("failed echo command");

let awk = Command::new("awk")
.arg("{print $1}")
.arg("{print $1 \" \" $2}")
.stdin(lsof.stdout.unwrap())
.stdout(Stdio::piped())
.spawn()
Expand All @@ -103,17 +103,10 @@ fn fd_report() {
let sort_again = Command::new("sort")
.args(["-r", "-n"])
.stdin(uniq.stdout.unwrap())
.stdout(Stdio::piped())
.spawn()
.expect("Fail sort again");

let head = Command::new("head")
.args(["-n", "20"])
.stdin(sort_again.stdout.unwrap())
.output()
.expect("Head failed");
.expect("Fail sort again");

let report = String::from_utf8_lossy(&head.stdout);
let report = String::from_utf8_lossy(&sort_again.stdout);

println!("{}", report);
}
Expand Down

0 comments on commit c7e1c8d

Please sign in to comment.