How to get core count from shell?

We are currently implementing support for parallel blocklist processing in adblock-lean and we would like to have an 'auto' mode which would detect CPU core count automatically and set the number of parallel jobs based on that.

However I couldn't find a built-in utility included with OpenWrt by default which would just print this information. Perhaps this is available via ubus in some way?

Installing packages is not a solution because we do not want adblock-lean to have extra dependencies.

If there is not better way, we may end up using

grep -c '^processor\s*:' /proc/cpuinfo

However I'm not sure how reliable this method is.

Any ideas would be appreciated.

Since nproc is not available in a default installation, I think there's no better way to determine core/thread count than what you are currently planning.

1 Like

Proc CPU info is reliable. If you have disk space install additional tooling but grep cpuinfo is good enough.

1 Like