public
Rubygem
Description: Ruby process monitor
Homepage: http://god.rubyforge.org
Clone URL: git://github.com/mojombo/god.git
Search Repo:
Click here to lend your support to: god and make a donation at www.pledgie.com !
god / lib / god / system / process.rb
100644 42 lines (34 sloc) 0.813 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module God
  module System
  
    class Process
      def initialize(pid)
        @pid = pid.to_i
        @poller = 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