From 8f9956b9fe3cb4acc6d14e3a47270062d0bc22f8 Mon Sep 17 00:00:00 2001 From: Thibaut Ackermann Date: Wed, 30 Oct 2019 21:55:27 +0100 Subject: [PATCH] Implement sched::sched_getaffinity() sched_getaffinity(2) get a process's CPU affinity mask --- src/sched.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/sched.rs b/src/sched.rs index 67188c57ee..6a50c639fd 100644 --- a/src/sched.rs +++ b/src/sched.rs @@ -96,6 +96,22 @@ mod sched_linux_like { Errno::result(res).map(drop) } + pub fn sched_getaffinity(pid: Pid) -> Result { + let mut cpuset = CpuSet::new(); + let res = unsafe { + libc::sched_getaffinity( + pid.into(), + mem::size_of::() as libc::size_t, + & mut cpuset.cpu_set, + ) + }; + + match res { + 0 => Ok(cpuset), + _ => Err(Error::from_errno(Errno::from_i32(res))), + } + } + pub fn clone( mut cb: CloneCb, stack: &mut [u8],