module Process
def get_affinity(int = Process.pid)
(0..mask).to_a.map{ |n| mask[n] }
mask = Process.get_affinity.first
this approach:
indicating the flag value of each processor, you can use something like
If you want to convert a decimal bit vector into an array of 0's and 1's
Process.get_affinity # => [[9], [15]]
# System has 4 processors, current process only allowed on 1 and 4.
Process.get_affinity # => [[15], [15]], where '15' is 1 + 2 + 4 + 8
# System has 4 processors, current process is allowed to run on all.
Example:
system.
which each bit represents the processors that are configured into a
process is allowed to run on. A system affinity mask is a bit vector in
A process affinity mask is a bit vector indicating the processors that a
containing the system affinity mask. Both are decimal values.
array, with the first containing the process affinity mask, and the second
current process if no pid is provided. The return value is a two element
Returns the process and system affinity mask for the given +pid+, or the
def get_affinity(int = Process.pid) pmask = FFI::MemoryPointer.new(:ulong) smask = FFI::MemoryPointer.new(:ulong) if int == Process.pid unless GetProcessAffinityMask(GetCurrentProcess(), pmask, smask) raise SystemCallError, FFI.errno, "GetProcessAffinityMask" end else begin handle = OpenProcess(PROCESS_QUERY_INFORMATION, 0 , int) if handle == 0 raise SystemCallError, FFI.errno, "OpenProcess" end unless GetProcessAffinityMask(handle, pmask, smask) raise SystemCallError, FFI.errno, "GetProcessAffinityMask" end ensure CloseHandle(handle) end end [pmask.read_ulong, smask.read_ulong] end