func main() { runtime.LockOSThread() t := thread.Current() fmt.Println("Current thread:", t) var p sched.Param policy, err := t.SchedPolicy() checkErr(err) err = t.SchedParam(&p) checkErr(err) fmt.Printf("Current policy/priority: %s/%d\n", policy, p.Priority) p.Priority = sched.FIFO.MaxPriority() err = t.SetSchedPolicy(sched.FIFO, &p) checkErr(err) policy, err = t.SchedPolicy() checkErr(err) err = t.SchedParam(&p) checkErr(err) fmt.Printf("New policy/priority: %s/%d\n", policy, p.Priority) }
func setRealtimeSched(what string, prio100 int) { runtime.LockOSThread() if os.Geteuid() != 0 { fmt.Fprintln(os.Stderr, what+": can't set realtime scheduling: no root priv.") return } t := thread.Current() fmt.Fprintf( os.Stderr, "%s: realtime sheduling prio %d%% for thread %d", what, prio100, t, ) p := sched.Param{ Priority: sched.FIFO.MaxPriority() * prio100 / 100, } checkErr(t.SetSchedPolicy(sched.FIFO, &p)) }