struct Hardware::PID
- Hardware::PID
- Struct
- Value
- Object
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
loop do
sleep 1
pid.cpu_usage # => 1.5
app.cpu_usage.to_i # => 4
end
Defined in:
hardware/pid.crConstructors
-
.new(pid : Int32 = Process.pid, cpu_total : Bool = true)
Creates a new
Hardware::PIDSet to false to avoid setting#cpu_total_current(useful if lots ofHardware::PIDare used) -
.new(executable : String, cpu_total = true)
Creates a new
Hardware::PIDby finding theexecutable's pid.
Class Method Summary
-
.all(cpu_total = false, &) : Nil
Yields a
Hardware::PIDfor each PID present on the system. -
.cpu_total_current : Int32
Used to avoid duplicate operations when lots of
Hardware::PIDare created (like a top implementation) -
.cpu_total_current=(cpu_total_current : Int32)
Used to avoid duplicate operations when lots of
Hardware::PIDare created (like a top implementation) -
.get_pids(executable : String) : Array(Int32)
Return all pids corresponding of a given
executablename.
Instance Method Summary
-
#cmdline : String
Returns
/proc/``#pid``/cmdline. -
#command : String
Returns a
Stringrepresentation of/proc/``#pid``/cmdline. -
#cpu_time(children = false) : Int32
Returns the CPU time without including ones from
childrenprocesses. -
#cpu_time_previous : Int32
Previous
#cpu_time. -
#cpu_time_previous=(cpu_time_previous : Int32)
Previous
#cpu_time. -
#cpu_total_previous : Int32
Previous
CPU.new.total. -
#cpu_total_previous=(cpu_total_previous : Int32)
Previous
CPU.new.total. -
#cpu_usage : Float32
Returns the CPU used in percentage.
-
#exe : String
Returns
/proc/``#pid``/exeif readable. - #exists? : Bool
-
#memory : Int32
Returns the actual memory used by the process.
- #name : String
-
#net : Net
Returns
Hardware::Netfor#pid -
#pid : Int32
Pid number
-
#stat : Stat
Returns a parsed
/proc/``#pid``/stat. -
#statm : Array(Int32)
Returns a parsed
/proc/``#pid``/statm. -
#status : Hash(String, String)
Returns a parsed
/proc/``#pid``/status.
Constructor Detail
Creates a new Hardware::PID
Set to false to avoid setting #cpu_total_current (useful if lots of Hardware::PID are used)
Creates a new Hardware::PID by finding the executable's pid.
Class Method Detail
Yields a Hardware::PID for each PID present on the system.
Used to avoid duplicate operations when lots of Hardware::PID are created (like a top implementation)
Used to avoid duplicate operations when lots of Hardware::PID are created (like a top implementation)
Return all pids corresponding of a given executable name.
Instance Method Detail
Returns the CPU time without including ones from children processes.