#Get list of currently running processes
41 messages Β· Page 1 of 1 (latest)
the sysinfo crate has the functions you need https://docs.rs/sysinfo/0.27.5/sysinfo/trait.SystemExt.html#tymethod.processes
Contains all the methods of the [System][crate::System] type.
I couldn't get it doing anything :/
I tried for 17 minutes straight since you answered...
I just don't understand it π¦
fn main() {
use sysinfo::{Pid, ProcessExt, System, SystemExt};
let s = System::new_all();
for (pid, process) in s.processes() {
println!("{} {}", pid, process.name());
}
}
...
190 scsi_eh_0
907 nvidia-modeset/
201 scsi_tmf_5
46 kworker/7:0-events
169 irq/31-aerdrv
2113 xmonad-x86_64-l
4899 Web Content
842 kworker/5:1H-kblockd
197 scsi_tmf_3
1856 wpa_supplicant
183 kworker/8:2-events
just tried it on my computer
That looks a lot easier than I tried to do...
π its copy paste from that link above

i tried π
Thank you tho π
oh also you can limit the amount of data it loads by switching out the new_all
the new_all loads everything sysinfo can get from the system
I'm going to load everything I can 
duplicates the entire system. um, wasn't expecting that
/j
casually goes through all processes and kills them.
can the kernel kill itself if it's the one doing the killing 
If you cut of your leg, where does it hurt... in your leg...?
fair point
Oh, also, do you know by any chance how I can repeat something with delay, but without freezing whole program?
is the program already async or just normal?
It's just born, it can choose its identity now
I think async would be great for my task tho
use std::{thread, time::Duration};
thread::spawn(move || {
thread::sleep(Duration::from_millis(100));
// do the thing
});
for the not async way
And for the async way?
If it's some 40 liner Im gonna 
I just never worked with async stuff π
tokio::spawn(async {
tokio::time::sleep(Duration::from_millis(100)).await;
// do the thing
});
Tokio is a runtime for writing reliable asynchronous applications with Rust. It provides async I/O, networking, scheduling, timers, and more.
the biggest rust async runtime
Cool! 
there is also https://async.rs/ for a more minimal approach
it won't be useful for reading the list of processes though
yeah ... we went to another question
It's not as much for reading list of processes as for managing them
if you do use async, the sysinfo call should be put in a https://docs.rs/tokio/latest/tokio/task/fn.spawn_blocking.html so it doesn't slow down other stuff
Runs the provided closure on a thread where blocking is acceptable.