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 : Int64 = Process.pid) #

Creates a new Hardware::PID.


def self.new(executable : String) #

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


Class Method Detail

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

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


def self.get_pids(executable : String, & : Int64 -> ) #

Yield each pids corresponding to a given executable name.


Instance Method Detail

def cmdline : String #

Returns /proc/``#pid``/cmdline.


def command : String #

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


def exe : String #

Returns /proc/``#pid``/exe if readable.


def exists? : Bool #

def memory : Int32 #

Returns the actual memory used by the process.


def name : String #

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


def net : Net #

Returns Hardware::Net for #pid


def number : Int64 #

Pid number


def stat(cpu : CPU | Nil = 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

def statm : Array(Int32) #

Returns a parsed /proc/``#pid``/statm.


def status : Status #

Returns a parsed /proc/``#pid``/status.