struct Hardware::PID

Overview

All informations related to the Processes running on your sytem, defined by Process IDentifiers.

pid = Hardware::PID.new           # Default is Process.pid
app = Hardware::PID.new "firefox" # Take the first matching PID

Defined in:

pid.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(number : Int32 = Process.pid) #

Creates a new Hardware::PID.


[View source]
def self.new(executable : String) #

Creates a new Hardware::PID by finding the executable's pid.


[View source]

Class Method Detail

def self.each(& : PID -> ) : Nil #

Yields a Hardware::PID for each PID present on the system.


[View source]
def self.get_pids(executable : String, & : Int32 -> ) #

Yield each pids corresponding to a given executable name.


[View source]

Instance Method Detail

def cmdline : String #

Returns /proc/#pid/cmdline.


[View source]
def command : String #

Returns a String representation of /proc/#pid/cmdline.


[View source]
def exe : String #

Returns /proc/#pid/exe if readable.


[View source]
def exists? : Bool #

[View source]
def memory : Int32 #

Returns the actual memory used by the process.


[View source]
def name : String #

Returns the PID name based on #exe or #cmdline.


[View source]
def net : Net #

Returns Hardware::Net for #pid


[View source]
def number : Int32 #

Pid number


[View source]
def stat(cpu : CPU? = CPU.new) : Stat #

Returns a parsed /proc/#pid/stat.

Have CPU information of the process.

pid_stat = Hardware::PID.new.stat
loop do
  sleep 1
  p pid_stat.cpu_usage! # => 1.5
end

[View source]
def statm : Array(Int32) #

Returns a parsed /proc/#pid/statm.


[View source]
def status : Status #

Returns a parsed /proc/#pid/status.


[View source]