How to Find Out the Number of CPU's on a Local Machine in Go
Created
Modified
Using runtime.NumCPU Function
The runtime.NumCPU()
method returns the number of logical CPUs usable by the current process.
The set of available CPUs is checked by querying the operating system at process startup. Changes to operating system CPU allocation after process startup are not reflected.
See the following example:
package main
import (
"fmt"
"runtime"
)
func main() {
cpus := runtime.NumCPU()
fmt.Println(cpus)
}
4