Skip to content

sysconf(_SC_NPROCESSORS_ONLN) will not always return total number of CPUs #5

@samuelvenable

Description

@samuelvenable

I would investigate how lscpu does it on Linux by seeing its source code and whether it is exposed outside of the kernel for normal user access.

return sysconf(_SC_NPROCESSORS_ONLN);

This command gets the desired information:

lscpu | grep 'CPU(s):' | uniq | cut -d' ' -f4- | awk 'NR==1{$1=$1;print}'

sysconf(_SC_NPROCESSORS_ONLN) gets the number of online CPUs, if any of them are offline then you will get a value you are not looking for.

I might fix this in a future PR when I have time. Just wanted to document this here for later.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions