From 65c90d5b45e91376bdd9aed4add32913ff474040 Mon Sep 17 00:00:00 2001 From: Jelle Besseling Date: Wed, 5 Apr 2023 20:12:01 +0200 Subject: [PATCH] Add ppid to ps command (#8750) # Description Adds the `ppid` field that's available on all supported platforms to the `ps` command. This would be useful in my scripts. # User-Facing Changes - ps output now contains an extra column # Tests + Formatting Not sure if I need to add a test for this # After Submitting Update https://www.nushell.sh/book/quick_tour.html#quick-tour to show the new table --- crates/nu-command/src/system/ps.rs | 6 ++++++ crates/nu-system/src/linux.rs | 5 +++++ crates/nu-system/src/macos.rs | 5 +++++ crates/nu-system/src/windows.rs | 5 +++++ 4 files changed, 21 insertions(+) diff --git a/crates/nu-command/src/system/ps.rs b/crates/nu-command/src/system/ps.rs index 5ebf21b3b..071366440 100644 --- a/crates/nu-command/src/system/ps.rs +++ b/crates/nu-command/src/system/ps.rs @@ -86,6 +86,12 @@ fn run_ps(engine_state: &EngineState, call: &Call) -> Result i32 { + self.ppid + } + /// Name of command pub fn name(&self) -> String { self.command() diff --git a/crates/nu-system/src/macos.rs b/crates/nu-system/src/macos.rs index 6227e4f90..63a840980 100644 --- a/crates/nu-system/src/macos.rs +++ b/crates/nu-system/src/macos.rs @@ -302,6 +302,11 @@ impl ProcessInfo { self.pid } + /// Parent PID of process + pub fn ppid(&self) -> i32 { + self.ppid + } + /// Name of command pub fn name(&self) -> String { if let Some(path) = &self.curr_path { diff --git a/crates/nu-system/src/windows.rs b/crates/nu-system/src/windows.rs index 9bd89784d..ebc85f91c 100644 --- a/crates/nu-system/src/windows.rs +++ b/crates/nu-system/src/windows.rs @@ -1006,6 +1006,11 @@ impl ProcessInfo { self.pid } + /// Parent PID of process + pub fn ppid(&self) -> i32 { + self.ppid + } + /// Name of command pub fn name(&self) -> String { self.command.clone()