github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/pkg/sysinfo/numcpu_linux.go (about) 1 package sysinfo // import "github.com/Prakhar-Agarwal-byte/moby/pkg/sysinfo" 2 3 import "golang.org/x/sys/unix" 4 5 // numCPU queries the system for the count of threads available 6 // for use to this process. 7 // 8 // Returns 0 on errors. Use |runtime.NumCPU| in that case. 9 func numCPU() int { 10 // Gets the affinity mask for a process: The very one invoking this function. 11 var mask unix.CPUSet 12 err := unix.SchedGetaffinity(0, &mask) 13 if err != nil { 14 return 0 15 } 16 return mask.Count() 17 }