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_used # => 1.5
app.cpu_used.to_i # => 4
end
Defined in:
hardware/pid.crConstructors
-
.new(pid : Int32 = Process.pid, cpu_time : Bool = true, 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_time = true, cpu_total = true)
Creates a new
Hardware::PIDby finding theexecutable's pid.
Class Method Summary
-
.all(cpu_time = false, cpu_total = false, &)
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)
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)
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.info[:total]. -
#cpu_total_previous=(cpu_total_previous : Int32)
Previous
CPU.new.info[:total]. -
#cpu_used : Float32
Returns the CPU used in percentage.
-
#exe : String | Nil
Returns
/proc/``#pid``/exeif readable. -
#memory
Returns the actual memory used by the process.
- #name
-
#net
Returns
Hardware::Netfor#pid -
#pid : Int32
Pid number
-
#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)
Instance Method Detail
Returns the CPU time without including ones from children processes.