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-10 16:59:12 +00:00
|
|
|
use crate::object::{ShellObject, Value};
|
2019-05-13 17:30:51 +00:00
|
|
|
use crate::prelude::*;
|
2019-05-11 08:08:21 +00:00
|
|
|
use crate::Command;
|
2019-05-10 16:59:12 +00:00
|
|
|
use derive_new::new;
|
2019-05-11 08:08:21 +00:00
|
|
|
use std::cell::RefCell;
|
|
|
|
use std::rc::Rc;
|
2019-05-10 16:59:12 +00:00
|
|
|
use sysinfo::SystemExt;
|
|
|
|
|
2019-05-11 08:08:21 +00:00
|
|
|
#[derive(new)]
|
2019-05-15 16:12:38 +00:00
|
|
|
pub struct PsBlueprint;
|
2019-05-11 08:08:21 +00:00
|
|
|
|
|
|
|
impl crate::CommandBlueprint for PsBlueprint {
|
|
|
|
fn create(
|
|
|
|
&self,
|
2019-05-13 17:30:51 +00:00
|
|
|
args: Vec<Value>,
|
2019-05-11 08:08:21 +00:00
|
|
|
host: &dyn crate::Host,
|
|
|
|
env: &mut crate::Environment,
|
2019-05-11 22:59:57 +00:00
|
|
|
) -> Result<Box<dyn Command>, ShellError> {
|
2019-05-15 16:12:38 +00:00
|
|
|
Ok(Box::new(Ps::new()))
|
2019-05-11 08:08:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-10 16:59:12 +00:00
|
|
|
#[derive(new)]
|
2019-05-15 16:12:38 +00:00
|
|
|
pub struct Ps;
|
2019-05-10 16:59:12 +00:00
|
|
|
|
|
|
|
impl crate::Command for Ps {
|
2019-05-13 17:30:51 +00:00
|
|
|
fn run(&mut self, stream: VecDeque<Value>) -> Result<VecDeque<ReturnValue>, ShellError> {
|
2019-05-15 16:12:38 +00:00
|
|
|
let mut system = sysinfo::System::new();
|
2019-05-11 08:08:21 +00:00
|
|
|
system.refresh_all();
|
2019-05-10 16:59:12 +00:00
|
|
|
|
2019-05-11 08:08:21 +00:00
|
|
|
let list = system.get_process_list();
|
2019-05-10 16:59:12 +00:00
|
|
|
|
|
|
|
let list = list
|
|
|
|
.into_iter()
|
2019-05-15 21:44:06 +00:00
|
|
|
.map(|(_, process)| ReturnValue::Value(Value::Object(process_dict(process))))
|
2019-05-13 17:30:51 +00:00
|
|
|
.collect::<VecDeque<_>>();
|
2019-05-10 16:59:12 +00:00
|
|
|
|
2019-05-13 17:30:51 +00:00
|
|
|
Ok(list)
|
2019-05-10 16:59:12 +00:00
|
|
|
}
|
|
|
|
}
|