• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/workflows/H16-Mar-2021-

cmd/numcpus/H16-Mar-2021-

.cirrus.ymlH A D16-Mar-2021308

LICENSEH A D16-Mar-202111.1 KiB

README.mdH A D16-Mar-20211.5 KiB

example_test.goH A D16-Mar-20211.4 KiB

go.modH A D16-Mar-2021105

go.sumH A D16-Mar-2021207

numcpus.goH A D16-Mar-20212.1 KiB

numcpus_bsd.goH A D16-Mar-20211.4 KiB

numcpus_linux.goH A D16-Mar-20211.9 KiB

numcpus_linux_test.goH A D16-Mar-20211.2 KiB

numcpus_solaris.goH A D16-Mar-20211.3 KiB

numcpus_test.goH A D16-Mar-20212.7 KiB

numcpus_unsupported.goH A D16-Mar-20211.1 KiB

README.md

1# numcpus
2
3[![Go Reference](https://pkg.go.dev/badge/github.com/tklauser/numcpus.svg)](https://pkg.go.dev/github.com/tklauser/numcpus)
4[![GitHub Action Status](https://github.com/tklauser/numcpus/workflows/Tests/badge.svg)](https://github.com/tklauser/numcpus/actions?query=workflow%3ATests)
5[![Go Report Card](https://goreportcard.com/badge/github.com/tklauser/numcpus)](https://goreportcard.com/report/github.com/tklauser/numcpus)
6
7Package numcpus provides information about the number of CPU.
8
9It gets the number of CPUs (online, offline, present, possible or kernel
10maximum) on a Linux, Darwin, FreeBSD, NetBSD, OpenBSD,  DragonflyBSD or
11Solaris/Illumos system.
12
13On Linux, the information is retrieved by reading the corresponding CPU
14topology files in `/sys/devices/system/cpu`.
15
16Not all functions are supported on Darwin, FreeBSD, NetBSD, OpenBSD,
17DragonflyBSD and Solaris/Illumos.
18
19## Usage
20
21```Go
22package main
23
24import (
25	"fmt"
26	"os"
27
28	"github.com/tklauser/numcpus"
29)
30
31func main() {
32	online, err := numcpus.GetOnline()
33	if err != nil {
34		fmt.Fprintf(os.Stderr, "GetOnline: %v\n", err)
35	}
36	fmt.Printf("online CPUs: %v\n", online)
37
38	possible, err := numcpus.GetPossible()
39	if err != nil {
40		fmt.Fprintf(os.Stderr, "GetPossible: %v\n", err)
41	}
42	fmt.Printf("possible CPUs: %v\n", possible)
43}
44```
45
46## References
47
48* [Linux kernel sysfs documenation for CPU attributes](https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-devices-system-cpu)
49* [Linux kernel CPU topology documentation](https://www.kernel.org/doc/Documentation/cputopology.txt)
50