GuillaumeGomez / sysinfo

Cross-platform library to fetch system information
MIT License
2.19k stars 320 forks source link

`processes()` return many non-existent processes #1337

Closed 21pages closed 3 months ago

21pages commented 3 months ago

version: 0.31.2

Screenshot from 2024-08-06 16-38-26

GuillaumeGomez commented 3 months ago

I see at least 3 gedit processes from ps. Interestingly enough, the 158332 and 158334 PIDs are not listed by sysinfo either.

21pages commented 3 months ago

Only one gedit exists, ps only list one, sysinfo list others

Screenshot from 2024-08-06 16-44-15

GuillaumeGomez commented 3 months ago

Nope, there are \n characters, so definitely not one. Use println!("output: {}", String::from_utf8(output.stdout).unwrap()) instead.

21pages commented 3 months ago

Screenshot from 2024-08-06 16-47-12

GuillaumeGomez commented 3 months ago

Oh so it was listing grep and ps. I see.

Take a look at /proc/[PID] for each of them. My guess here is that some of them are subprocesses.

21pages commented 3 months ago

not exist in /proc/, it's easy to reproduce.

GuillaumeGomez commented 3 months ago

And in /proc/[PID]/task/[sub PID]?

GuillaumeGomez commented 3 months ago

Also, what is htop displaying?

21pages commented 3 months ago

Multi gedit in htop, seems the same as 0.31, but version 0.29 give one pid, same as ps

GuillaumeGomez commented 3 months ago

So maybe check Process::thread_kind()? I should maybe add a Process::is_task method though...

21pages commented 3 months ago

Filter thread_kind seems work. Screenshot from 2024-08-06 18-56-17

This is the first time I've heard of subprocesses, I think most people just use the main process.

GuillaumeGomez commented 3 months ago

Well, computers are complicated. :)