Home »
Golang »
Golang FAQ
How to find the number of CPU Cores used by the current process in Golang?
Learn, how to find the number of CPU cores using used by the current process.
Submitted by IncludeHelp, on October 19, 2021
In the Go programming language – to find the number of CPU cores, we use the NumCPU() function of the "runtime" package.
The NumCPU() function returns the number of logical CPUs usable by the current process.
Syntax:
func NumCPU() int
Program:
// Go language program to find the
// number of CPU Cores
package main
import (
"fmt"
"runtime"
)
// Main function
func main() {
// Get number of processors
// using the NumCPU() function
fmt.Println("The number of CPU Cores:", runtime.NumCPU())
}
Output:
The number of CPU Cores: 8
Golang FAQ »