From 2a0886585124b924e4944b354f3473407a6ee409 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Tue, 12 Sep 2023 14:50:05 -0500 Subject: [PATCH] add a few more columns to linux `ps -l` output (#10344) # Description This PR tried to add a few more columns to the Linux `ps -l` command. Those columns are: * start_time * user_id * priority * process_threads There are a few that I left commented out that could be added but the screen was beginning to look crowded. So, I left out: * group_id * session_id * tgp_id (which could be helpful for eventual job control) And there's like 100 more things that could be added that didn't seem especially useful right now. ![image](https://github.com/nushell/nushell/assets/343840/065c0538-8f7d-4c9f-871f-a1bc98aff9d1) # User-Facing Changes # Tests + Formatting # After Submitting --- crates/nu-command/src/system/ps.rs | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/crates/nu-command/src/system/ps.rs b/crates/nu-command/src/system/ps.rs index 86ad0d6979..c87f72e050 100644 --- a/crates/nu-command/src/system/ps.rs +++ b/crates/nu-command/src/system/ps.rs @@ -1,11 +1,20 @@ #[cfg(windows)] use itertools::Itertools; +#[cfg(all( + unix, + not(target_os = "macos"), + not(target_os = "windows"), + not(target_os = "android"), + not(target_os = "ios") +))] +use nu_protocol::Span; use nu_protocol::{ ast::Call, engine::{Command, EngineState, Stack}, Category, Example, IntoInterruptiblePipelineData, PipelineData, Record, ShellError, Signature, Type, Value, }; + use std::time::Duration; #[derive(Clone)] @@ -101,6 +110,40 @@ fn run_ps(engine_state: &EngineState, call: &Call) -> Result t, + Err(_) => { + // If we can't get the start time, just use the current time + chrono::Local::now() + } + }; + record.push("start_time", Value::date(proc_start.into(), span)); + record.push("user_id", Value::int(proc.curr_proc.owner() as i64, span)); + // These work and may be helpful, but it just seemed crowded + // record.push("group_id", Value::int(proc_stat.pgrp as i64, span)); + // record.push("session_id", Value::int(proc_stat.session as i64, span)); + // This may be helpful for ctrl+z type of checking, once we get there + // record.push("tpg_id", Value::int(proc_stat.tpgid as i64, span)); + record.push("priority", Value::int(proc_stat.priority, span)); + record.push("process_threads", Value::int(proc_stat.num_threads, span)); + } #[cfg(windows)] { //TODO: There's still more information we can cram in there if we want to