Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'windows/process'
- require 'windows/handle'
- module Process
- class << self
- include Windows::Process
- include Windows::Handle
- PRIO_SYM_MAP = {
- ABOVE_NORMAL_PRIORITY_CLASS => :above_normal,
- BELOW_NORMAL_PRIORITY_CLASS => :below_normal,
- HIGH_PRIORITY_CLASS => :high,
- IDLE_PRIORITY_CLASS => :idle,
- NORMAL_PRIORITY_CLASS => :normal,
- REALTIME_PRIORITY_CLASS => :realtime,
- }
- SYM_PRIO_MAP = PRIO_SYM_MAP.invert
- def getpriority(pid)
- if (hp = OpenProcess(PROCESS_ALL_ACCESS, 0, $$)) != 0
- begin
- r = GetPriorityClass(hp)
- PRIO_SYM_MAP[r] || r
- ensure
- CloseHandle(hp)
- end
- else
- false
- end
- end
- def setpriority(pid, prio)
- if (hp = OpenProcess(PROCESS_ALL_ACCESS, 0, $$)) != 0
- begin
- case prio
- when Integer
- PRIO_SYM_MAP[prio] or prio = nil
- when Symbol
- prio = SYM_PRIO_MAP[prio]
- else
- prio = nil
- end
- prio and SetPriorityClass(hp, prio) != 0
- ensure
- CloseHandle(hp)
- end
- else
- false
- end
- end
- end
- end
- p Process.setpriority($$, :high)
- p Process.getpriority($$)
Add Comment
Please, Sign In to add comment