2020-05-19 18:20:18 +02:00
|
|
|
+++
|
|
|
|
title = "Linux: HOWTO get the number of CPUs"
|
|
|
|
date = 2013-11-13T12:13:04+00:00
|
2023-10-26 11:53:38 +02:00
|
|
|
[taxonomies]
|
|
|
|
tags = ["linux", "fedora"]
|
2020-05-19 18:20:18 +02:00
|
|
|
+++
|
|
|
|
```console
|
|
|
|
$ getconf _NPROCESSORS_ONLN
|
|
|
|
```
|
|
|
|
returns the number of CPUs online.
|
|
|
|
|
|
|
|
<!-- more -->
|
|
|
|
|
|
|
|
Internally it is parsing
|
|
|
|
`/sys/devices/system/cpu/online`, which can have the contents: `0-3,5,7-9`.
|
|
|
|
|
|
|
|
Better let getconf [do all the counting for you](https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/getsysstats.c#l127).
|
|
|
|
|
|
|
|
This is very useful, if you want to optimize the number of threads.
|