[Win32utils-devel] Process.getpriority implementation

Daniel Berger djberg96 at gmail.com
Thu Jul 16 01:45:23 EDT 2009


Hi,

How does this look for a Process.getpriority implementation for Windows?

   # Retrieves the priority class for the specified process id +int+. Unlike
   # the default implementation, lower values do not necessarily correspond
to
   # higher priority classes.
   #
   # 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 return values are:
   #
   # 32    - NORMAL_PRIORITY_CLASS
   # 64    - IDLE_PRIORITY_CLASS
   # 128   - HIGH_PRIORITY_CLASS
   # 256   - REALTIME_PRIORITY_CLASS
   # 16384 - BELOW_NORMAL_PRIORITY_CLASS
   # 32768 - ABOVE_NORMAL_PRIORITY_CLASS
   # 
   def getpriority(kind = nil, int = nil)
      raise ArgumentError unless int

      handle = OpenProcess(PROCESS_QUERY_INFORMATION, 0 , int)

      if handle == INVALID_HANDLE_VALUE
         raise Error, get_last_error
      end

      priority_class = GetPriorityClass(handle)

      if priority_class == 0
         raise Error, get_last_error
      end

      priority_class
   end



More information about the win32utils-devel mailing list