mirror of
https://github.com/nushell/nushell.git
synced 2024-12-26 00:50:03 +01:00
fix the ps command's virtual mem (#3007)
This commit is contained in:
parent
3083346884
commit
67aaf4cb2d
@ -17,40 +17,42 @@ pub async fn ps(tag: Tag, long: bool) -> Result<Vec<Value>, ShellError> {
|
||||
sys.refresh_all();
|
||||
let duration = std::time::Duration::from_millis(500);
|
||||
std::thread::sleep(duration);
|
||||
sys.refresh_all();
|
||||
|
||||
let mut output = vec![];
|
||||
|
||||
let result = sys.get_processes();
|
||||
let result: Vec<_> = sys.get_processes().iter().map(|x| *x.0).collect();
|
||||
|
||||
for (pid, process) in result.iter() {
|
||||
for pid in result.into_iter() {
|
||||
sys.refresh_process(pid);
|
||||
if let Some(result) = sys.get_process(pid) {
|
||||
let mut dict = TaggedDictBuilder::new(&tag);
|
||||
dict.insert_untagged("pid", UntaggedValue::int(*pid));
|
||||
dict.insert_untagged("name", UntaggedValue::string(process.name()));
|
||||
dict.insert_untagged("pid", UntaggedValue::int(pid));
|
||||
dict.insert_untagged("name", UntaggedValue::string(result.name()));
|
||||
dict.insert_untagged(
|
||||
"status",
|
||||
UntaggedValue::string(format!("{:?}", process.status())),
|
||||
UntaggedValue::string(format!("{:?}", result.status())),
|
||||
);
|
||||
dict.insert_untagged(
|
||||
"cpu",
|
||||
UntaggedValue::decimal_from_float(process.cpu_usage() as f64, tag.span),
|
||||
UntaggedValue::decimal_from_float(result.cpu_usage() as f64, tag.span),
|
||||
);
|
||||
dict.insert_untagged("mem", UntaggedValue::filesize(process.memory() * 1000));
|
||||
dict.insert_untagged("mem", UntaggedValue::filesize(result.memory() * 1000));
|
||||
dict.insert_untagged(
|
||||
"virtual",
|
||||
UntaggedValue::filesize(process.virtual_memory() * 1000),
|
||||
UntaggedValue::filesize(result.virtual_memory() * 1000),
|
||||
);
|
||||
|
||||
if long {
|
||||
if let Some(parent) = process.parent() {
|
||||
if let Some(parent) = result.parent() {
|
||||
dict.insert_untagged("parent", UntaggedValue::int(parent));
|
||||
}
|
||||
dict.insert_untagged("exe", UntaggedValue::filepath(process.exe()));
|
||||
dict.insert_untagged("command", UntaggedValue::string(process.cmd().join(" ")));
|
||||
dict.insert_untagged("exe", UntaggedValue::filepath(result.exe()));
|
||||
dict.insert_untagged("command", UntaggedValue::string(result.cmd().join(" ")));
|
||||
}
|
||||
|
||||
output.push(dict.into_value());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(output)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user