Sha256: 86183b3fc62e181bbb8caf1264aa5f929ad8743dfe37410399b0f6329ded4732

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module God
  module System
    class Process
      def self.fetch_system_poller
        @@poller ||= if SlashProcPoller.usable?
                       SlashProcPoller
                     else
                       PortablePoller
                     end
      end

      def initialize(pid)
        @pid = pid.to_i
        @poller = self.class.fetch_system_poller.new(@pid)
      end

      # Return true if this process is running, false otherwise
      def exists?
        !!::Process.kill(0, @pid) rescue false
      end

      # Memory usage in kilobytes (resident set size)
      def memory
        @poller.memory
      end

      # Percentage memory usage
      def percent_memory
        @poller.percent_memory
      end

      # Percentage CPU usage
      def percent_cpu
        @poller.percent_cpu
      end

      private

      def fetch_system_poller
        if SlashProcPoller.usable?
          SlashProcPoller
        else
          PortablePoller
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
resurrected_god-1.1.1 lib/god/system/process.rb
resurrected_god-1.1.0 lib/god/system/process.rb