jhpratt / num_threads

Obtain the number of threads in the current process
https://docs.rs/num_threads
Apache License 2.0
12 stars 7 forks source link

Use /proc/self/task or /proc/self/status when /proc/self/stat returns 0 #15

Open ptrcnull opened 1 year ago

ptrcnull commented 1 year ago

( follow-up to #3 )

in some weird cases, such as running qemu-user ( still debugging this issue ), /proc/self/stat returns mostly empty values, while /proc/self/task and /proc/self/status have the correct values:

$ cat /proc/self/stat
18477 (cat) R 16603 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 21552080 0 0 0 0 0 70368752569616 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
$ cat /proc/self/status | grep Thread
Threads:    2
$ ls /proc/self/task
18505  18507
$ 

it would be nice to have a fallback to those, in case they have correct values and /proc/self/stat doesn't

Freaky commented 12 months ago

I'd like to have a better idea what's going on before arbitrarily falling back to a different kernel interface in the hope that it'll give the right answer where a previous one didn't.

Is there something particularly about /proc/self/stat that might render it less reliable?