동일 실행파일을 여러개 실행시켰을 때 구분해서 affinity 설정

This commit is contained in:
2023-11-30 14:17:27 +09:00
parent 023a2a5194
commit 1d3266bbaf
6 changed files with 154 additions and 33 deletions

41
client/client_misc.go Normal file
View File

@ -0,0 +1,41 @@
//go:build !linux
package client
func set_affinity(pid int, cpu int) {
}
// package main
// import (
// "fmt"
// "syscall"
// "time"
// "unsafe"
// )
// func main() {
// var mask uintptr
// // Get the current CPU affinity of the process
// if _, _, err := syscall.RawSyscall(syscall.SYS_SCHED_GETAFFINITY, 0, uintptr(unsafe.Sizeof(mask)), uintptr(unsafe.Pointer(&mask))); err != 0 {
// fmt.Println("Failed to get CPU affinity:", err)
// return
// }
// fmt.Println("Current CPU affinity:", mask)
// // Set the new CPU affinity
// mask = 3
// if _, _, err := syscall.RawSyscall(syscall.SYS_SCHED_SETAFFINITY, 0, uintptr(unsafe.Sizeof(mask)), uintptr(unsafe.Pointer(&mask))); err != 0 {
// fmt.Println("Failed to set CPU affinity:", err)
// return
// }
// fmt.Println("New CPU affinity:", mask)
// // some code
// for {
// println("Hello, World!")
// time.Sleep(1 * time.Second)
// }
// }