1use std::fs::File;
2use crate::shared_functions::line;
3
4pub fn ppid(file: File) -> String {
5 let ppid = line(file, 6);
6 ppid.split(':').collect::<Vec<&str>>()[1].to_string()
7}
8
9pub fn name(ppid: String) -> String {
10 let path = format!("/proc/{}/status", ppid.trim());
11 let file = File::open(path).unwrap();
12 let line = line(file, 0);
13 line.split(':').collect::<Vec<&str>>()[1].to_string()
14}
15
16pub fn info(process_name: String, process_id: String) -> std::io::Result<String> {
17 if process_name.ends_with("sh")
18 || process_name == "ion"
19 || process_name == "screen"
20 || process_name == "tmux"
21 || process_name.starts_with("tmux")
22 {
23 let path = format!("/proc/{}/status", process_id);
24 let new_ppid = ppid(File::open(path)?).trim().replace("\n", "");
25 let new_name = name(new_ppid.clone()).trim().replace("\n", "");
26 if new_name.ends_with("sh")
27 || new_name == "ion"
28 || new_name == "screen"
29 || new_name == "tmux"
30 || new_name.starts_with("tmux")
31 {
32 let path = format!("/proc/{}/status", new_ppid);
33 let new_ppid = ppid(File::open(path)?).trim().replace("\n", "");
34 Ok(name(new_ppid).trim().replace("\n", ""))
35 } else {
36 Ok(new_name.trim().replace("\n", ""))
37 }
38 } else {
39 Ok(process_name.trim().replace("\n", ""))
40 }
41}