pub fn sched_setaffinity(pid: Pid, cpuset: &CpuSet) -> Result<()>
Expand description
sched_setaffinity
set a thread’s CPU affinity mask
(sched_setaffinity(2)
)
pid
is the thread ID to update.
If pid is zero, then the calling thread is updated.
The cpuset
argument specifies the set of CPUs on which the thread
will be eligible to run.
§Example
Binding the current thread to CPU 0 can be done as follows:
use nix::sched::{CpuSet, sched_setaffinity};
use nix::unistd::Pid;
let mut cpu_set = CpuSet::new();
cpu_set.set(0).unwrap();
sched_setaffinity(Pid::from_raw(0), &cpu_set).unwrap();