mirror of
https://github.com/status-im/status-go.git
synced 2025-02-21 11:18:28 +00:00
50 lines
1.5 KiB
Markdown
50 lines
1.5 KiB
Markdown
# numcpus
|
|
|
|
[](https://pkg.go.dev/github.com/tklauser/numcpus)
|
|
[](https://github.com/tklauser/numcpus/actions?query=workflow%3ATests)
|
|
[](https://goreportcard.com/report/github.com/tklauser/numcpus)
|
|
|
|
Package numcpus provides information about the number of CPU.
|
|
|
|
It gets the number of CPUs (online, offline, present, possible or kernel
|
|
maximum) on a Linux, Darwin, FreeBSD, NetBSD, OpenBSD, DragonflyBSD or
|
|
Solaris/Illumos system.
|
|
|
|
On Linux, the information is retrieved by reading the corresponding CPU
|
|
topology files in `/sys/devices/system/cpu`.
|
|
|
|
Not all functions are supported on Darwin, FreeBSD, NetBSD, OpenBSD,
|
|
DragonflyBSD and Solaris/Illumos.
|
|
|
|
## Usage
|
|
|
|
```Go
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/tklauser/numcpus"
|
|
)
|
|
|
|
func main() {
|
|
online, err := numcpus.GetOnline()
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "GetOnline: %v\n", err)
|
|
}
|
|
fmt.Printf("online CPUs: %v\n", online)
|
|
|
|
possible, err := numcpus.GetPossible()
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "GetPossible: %v\n", err)
|
|
}
|
|
fmt.Printf("possible CPUs: %v\n", possible)
|
|
}
|
|
```
|
|
|
|
## References
|
|
|
|
* [Linux kernel sysfs documenation for CPU attributes](https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-devices-system-cpu)
|
|
* [Linux kernel CPU topology documentation](https://www.kernel.org/doc/Documentation/cputopology.txt)
|