Skip to content
Snippets Groups Projects
Select Git revision
  • d05cffb65c67cefd72c580a4e1db0b4694a0ee84
  • master default protected
  • v1.23.2
  • v1.23.1
  • v1.23.0
  • v1.22.0
  • v1.21.1
  • v1.21.0
  • v1.20.3
  • v1.20.2
  • v1.20.1
  • v1.20.0
  • v1.19.4
  • v1.19.3
  • v1.19.2
  • v1.19.1
  • v1.19.0
  • v1.18.2
  • v1.18.1
  • v1.18.0
  • v1.17.0
  • v1.16.1
22 results

README.md

Blame
  • Volker Schukai's avatar
    61a1232e
    History
    README.md 1.60 KiB

    numcpus

    Go Reference GitHub Action Status

    Package numcpus provides information about the number of CPUs in the system.

    It gets the number of CPUs (online, offline, present, possible, configured or kernel maximum) on Linux, Darwin, FreeBSD, NetBSD, OpenBSD, DragonflyBSD or Solaris/Illumos systems.

    On Linux, the information is retrieved by reading the corresponding CPU topology files in /sys/devices/system/cpu.

    On BSD systems, the information is retrieved using the hw.ncpu and hw.ncpuonline sysctls, if supported.

    Not all functions are supported on Darwin, FreeBSD, NetBSD, OpenBSD, DragonflyBSD and Solaris/Illumos. ErrNotSupported is returned in case a function is not supported on a particular platform.

    Usage

    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