2019-05-10 16:59:12 +00:00
|
|
|
use crate::errors::ShellError;
|
2019-05-15 21:44:06 +00:00
|
|
|
use crate::object::process::process_dict;
|
2019-05-15 22:23:36 +00:00
|
|
|
use crate::object::Value;
|
2019-05-13 17:30:51 +00:00
|
|
|
use crate::prelude::*;
|
2019-05-10 16:59:12 +00:00
|
|
|
use sysinfo::SystemExt;
|
|
|
|
|
2019-05-22 07:12:03 +00:00
|
|
|
pub fn ps(_args: CommandArgs<'caller>) -> Result<VecDeque<ReturnValue>, ShellError> {
|
|
|
|
let mut system = sysinfo::System::new();
|
|
|
|
system.refresh_all();
|
2019-05-10 16:59:12 +00:00
|
|
|
|
2019-05-22 07:12:03 +00:00
|
|
|
let list = system.get_process_list();
|
2019-05-10 16:59:12 +00:00
|
|
|
|
2019-05-22 07:12:03 +00:00
|
|
|
let list = list
|
|
|
|
.into_iter()
|
|
|
|
.map(|(_, process)| ReturnValue::Value(Value::Object(process_dict(process))))
|
|
|
|
.collect::<VecDeque<_>>();
|
2019-05-10 16:59:12 +00:00
|
|
|
|
2019-05-22 07:12:03 +00:00
|
|
|
Ok(list)
|
2019-05-10 16:59:12 +00:00
|
|
|
}
|