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
This commit is contained in:
Jelle Besseling 2023-04-05 20:12:01 +02:00 committed by GitHub
parent 50ca77437d
commit 65c90d5b45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 0 deletions

View File

@ -86,6 +86,12 @@ fn run_ps(engine_state: &EngineState, call: &Call) -> Result<PipelineData, Shell
span,
});
cols.push("ppid".to_string());
vals.push(Value::Int {
val: proc.ppid() as i64,
span,
});
cols.push("name".to_string());
vals.push(Value::String {
val: proc.name(),

View File

@ -131,6 +131,11 @@ impl ProcessInfo {
self.pid
}
/// PPID of process
pub fn ppid(&self) -> i32 {
self.ppid
}
/// Name of command
pub fn name(&self) -> String {
self.command()

View File

@ -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 {

View File

@ -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()