Method: Process.setpriority

Defined in:
lib/win32/process.rb

.setpriority(kind, int, int_priority) ⇒ Object

Sets the priority class for the specified process id int.

The kind parameter is ignored but present for API compatibility. You can only retrieve process information, not process group or user information, so it is effectively always Process::PRIO_PROCESS.

Possible int_priority values are:

  • Process::NORMAL_PRIORITY_CLASS

  • Process::IDLE_PRIORITY_CLASS

  • Process::HIGH_PRIORITY_CLASS

  • Process::REALTIME_PRIORITY_CLASS

  • Process::BELOW_NORMAL_PRIORITY_CLASS

  • Process::ABOVE_NORMAL_PRIORITY_CLASS

Raises:

  • (TypeError)


139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/win32/process.rb', line 139

def setpriority(kind, int, int_priority)
  raise TypeError unless kind.is_a?(Integer)          # Match spec
  raise TypeError unless int.is_a?(Integer)           # Match spec
  raise TypeError unless int_priority.is_a?(Integer)  # Match spec

  int = Process.pid if int == 0                       # Match spec

  handle = OpenProcess(PROCESS_SET_INFORMATION, 0 , int)

  if handle == 0
    raise SystemCallError, FFI.errno, "OpenProcess"
  end

  begin
    unless SetPriorityClass(handle, int_priority)
      raise SystemCallError, FFI.errno, "SetPriorityClass"
    end
  ensure
    CloseHandle(handle)
  end

  0 # Match the spec
end