From c7e1c8da4bf73a1ebe04194850d9ec9a010e9125 Mon Sep 17 00:00:00 2001 From: Mattia Procopio Date: Tue, 11 Jan 2022 14:12:43 +0100 Subject: [PATCH] Fix PID duplication in report When monitoring FDs, merging values from the same program but with different PID was leading to wrong results --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 13 +++---------- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 25e1377..0882ceb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "astromonitor" -version = "0.4.0" +version = "0.4.1" dependencies = [ "chrono", "dirs", diff --git a/Cargo.toml b/Cargo.toml index 4068b0a..e40bfac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/src/main.rs b/src/main.rs index d9cb21d..799dc7e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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() @@ -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); }