| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "log" |
| 6 | |
| 7 | "golang.org/x/sys/unix" |
| 8 | ) |
| 9 | |
| 10 | func main() { |
| 11 | pid := 1 |
| 12 | |
| 13 | // init cpuset |
| 14 | var cpuset unix.CPUSet |
| 15 | |
| 16 | err := unix.SchedGetaffinity(pid, &cpuset) |
| 17 | if err != nil { |
| 18 | log.Fatalf("Error getting CPU affinity: %v\n", err) |
| 19 | } |
| 20 | |
| 21 | processorCount := 0 |
| 22 | |
| 23 | for i := 0; i < cpuset.Count(); i++ { |
| 24 | if cpuset.IsSet(i) { |
| 25 | processorCount++ |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | fmt.Printf("CPUSet size: %d, Number of processor allowed to pid %d is %d\n", cpuset.Count(), pid, processorCount) |
| 30 | } |
| 31 |
aquafire / test_cpu_affinity.go
Last active 6 months ago