1 #![allow(clippy::print_literal)]
2
3 extern crate procfs;
4
5 /// A very basic clone of `ps` on Linux, in the simple no-argument mode.
6 /// It shows all the processes that share the same tty as our self
7
main()8 fn main() {
9 let me = procfs::process::Process::myself().unwrap();
10 let tps = procfs::ticks_per_second().unwrap();
11
12 println!("{: >5} {: <8} {: >8} {}", "PID", "TTY", "TIME", "CMD");
13
14 let tty = format!("pty/{}", me.stat.tty_nr().1);
15 for prc in procfs::process::all_processes().unwrap() {
16 if prc.stat.tty_nr == me.stat.tty_nr {
17 // total_time is in seconds
18 let total_time = (prc.stat.utime + prc.stat.stime) as f32 / (tps as f32);
19 println!("{: >5} {: <8} {: >8} {}", prc.stat.pid, tty, total_time, prc.stat.comm);
20 }
21 }
22 }
23