Skip to content

Commit

Permalink
Implement sched::sched_getaffinity()
Browse files Browse the repository at this point in the history
sched_getaffinity(2) get a process's CPU affinity mask
  • Loading branch information
thib-ack committed Oct 30, 2019
1 parent 7a5248c commit 4e35a55
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ mod sched_linux_like {
Errno::result(res).map(drop)
}

pub fn sched_getaffinity(pid: Pid) -> Result<CpuSet> {
let mut cpuset = CpuSet::new();
let res = unsafe {
libc::sched_getaffinity(
pid.into(),
mem::size_of::<CpuSet>() as libc::size_t,
& mut cpuset.cpu_set,
)
};

match res {
0 => Ok(cpuset),
_ => Err(nix::Error::from_errno(Errno::from_i32(res))),
}
}

pub fn clone(
mut cb: CloneCb,
stack: &mut [u8],
Expand Down

0 comments on commit 4e35a55

Please sign in to comment.