Guest User

Untitled

a guest
Feb 21st, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. require 'rubygems'
  2. require 'windows/process'
  3. require 'windows/handle'
  4.  
  5. module Process
  6. class << self
  7. include Windows::Process
  8. include Windows::Handle
  9. PRIO_SYM_MAP = {
  10. ABOVE_NORMAL_PRIORITY_CLASS => :above_normal,
  11. BELOW_NORMAL_PRIORITY_CLASS => :below_normal,
  12. HIGH_PRIORITY_CLASS => :high,
  13. IDLE_PRIORITY_CLASS => :idle,
  14. NORMAL_PRIORITY_CLASS => :normal,
  15. REALTIME_PRIORITY_CLASS => :realtime,
  16. }
  17. SYM_PRIO_MAP = PRIO_SYM_MAP.invert
  18.  
  19. def getpriority(pid)
  20. if (hp = OpenProcess(PROCESS_ALL_ACCESS, 0, $$)) != 0
  21. begin
  22. r = GetPriorityClass(hp)
  23. PRIO_SYM_MAP[r] || r
  24. ensure
  25. CloseHandle(hp)
  26. end
  27. else
  28. false
  29. end
  30. end
  31.  
  32. def setpriority(pid, prio)
  33. if (hp = OpenProcess(PROCESS_ALL_ACCESS, 0, $$)) != 0
  34. begin
  35. case prio
  36. when Integer
  37. PRIO_SYM_MAP[prio] or prio = nil
  38. when Symbol
  39. prio = SYM_PRIO_MAP[prio]
  40. else
  41. prio = nil
  42. end
  43. prio and SetPriorityClass(hp, prio) != 0
  44. ensure
  45. CloseHandle(hp)
  46. end
  47. else
  48. false
  49. end
  50. end
  51. end
  52. end
  53. p Process.setpriority($$, :high)
  54. p Process.getpriority($$)
Add Comment
Please, Sign In to add comment