#Get list of currently running processes

41 messages Β· Page 1 of 1 (latest)

noble cedar
#

I need to get the list of all processes that are running now, I don't know if there is a library or built-in functionality

frigid tide
noble cedar
#

I tried for 17 minutes straight since you answered...

#

I just don't understand it 😦

frigid tide
# noble cedar I couldn't get it doing anything :/
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

noble cedar
#

That looks a lot easier than I tried to do...

frigid tide
noble cedar
frigid tide
#

i tried πŸ˜…

noble cedar
#

Thank you tho πŸ‘

frigid tide
#

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

noble cedar
#

I'm going to load everything I can ferrisBanne

frigid tide
#

duplicates the entire system. um, wasn't expecting that ferrisballSweat /j

noble cedar
#

casually goes through all processes and kills them.

frigid tide
#

can the kernel kill itself if it's the one doing the killing ferrisThink

noble cedar
frigid tide
#

fair point

noble cedar
#

Oh, also, do you know by any chance how I can repeat something with delay, but without freezing whole program?

frigid tide
noble cedar
#

It's just born, it can choose its identity now

#

I think async would be great for my task tho

frigid tide
#
use std::{thread, time::Duration};
thread::spawn(move || {
    thread::sleep(Duration::from_millis(100));
    // do the thing
});
#

for the not async way

noble cedar
#

And for the async way?

#

If it's some 40 liner Im gonna ferrisClueless

#

I just never worked with async stuff πŸ˜„

frigid tide
#
tokio::spawn(async {
    tokio::time::sleep(Duration::from_millis(100)).await;
    // do the thing
});
noble cedar
#

Tokio πŸ‡―πŸ‡΅ ????

frigid tide
#

the biggest rust async runtime

noble cedar
#

Cool! ferristhumbsup

frigid tide
noble wyvern
#

it won't be useful for reading the list of processes though

frigid tide
#

yeah ... we went to another question

noble cedar
frigid tide
noble wyvern
#

that's what I meant

#

getting the process list isn't async by itself