Project

ps-ruby

0.0
No commit activity in last 3 years
No release in over 3 years
PS-Ruby is a simple ps wrapper with ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

PS-Ruby

PS-Ruby is a simple ps wrapper with ruby. You can see example.rb to learn more...

installation

  gem install ps-ruby

Usage

Display all processes

  > require 'ps-ruby'
  > PS.simple_display
  PID   %CPU  %MEM  COMMAND
  36484 21.1  0.6   /Applications/Google Chrome.app...
  36140 19.0  1.0   /Applications/Google Chrome.app...
  67812 14.7  0.2   /Applications/Sublime Text.app/...
  67813 13.7  0.1   ruby example.rb
  ...

Display special processes by name

  > PS.simple_display("zsh")

or

  > PS.simple_display(/.*zsh.*/i)

or

  PS.find_processes("zsh").simple_display
  PID   %CPU  %MEM  COMMAND
  59395 0.4   0.0   -zsh
  67468 0.0   0.0   -zsh
  83005 0.0   0.0   -zsh

Get special processes by name

  > PS.find_processes("zsh")
  [{
    "USER" => "HondaDai", 
    "PID" => "59395", 
    "%CPU" => "0.4", 
    "%MEM" => "0.0", 
    "VSZ" => "2462760", 
    "RSS" => "3308", 
    "TT" => "s002", 
    "STAT" => "S", 
    "STARTED" => "2:21PM", 
    "TIME" => "0:00.75", 
    "COMMAND" => "-zsh"
  }, {
    "USER" => "HondaDai", 
    "PID" => "83005", 
    "%CPU" => "0.0", 
    "%MEM" => "0.0", 
    "VSZ" => "2462760", 
    "RSS" => "776", 
    "TT" => "s001", 
    "STAT" => "S+", 
    "STARTED" => "10:10PM", 
    "TIME" => "0:01.07", 
    "COMMAND" => "-zsh"
  }, {
    "USER" => "HondaDai", 
    "PID" => "67468", 
    "%CPU" => "0.0", 
    "%MEM" => "0.0", 
    "VSZ" => "2462760", 
    "RSS" => "196", 
    "TT" => "s000", 
    "STAT" => "S", 
    "STARTED" => "Fri03PM", 
    "TIME" => "0:00.78", 
    "COMMAND" => "-zsh"
  }]

Chaining

  > PS.find_processes("zsh").find_process_by("PID", "67468")
  [{
    "USER" => "HondaDai", 
    "PID" => "67468", 
    "%CPU" => "0.0", 
    "%MEM" => "0.0", 
    "VSZ" => "2462760", 
    "RSS" => "196", 
    "TT" => "s000", 
    "STAT" => "S", 
    "STARTED" => "Fri03PM", 
    "TIME" => "0:00.78", 
    "COMMAND" => "-zsh"
  }]
  ms = PS.find_processes("Microsoft")
  word = ms.find_processes("Word")
  ppt = ms.find_processes("PowerPoint")

Get special attribute

  commands = PS.find_processes("Microsoft").pick_attr("COMMAND")

Kill process

  > PS.find_processes("chrome").kill! # kill all processes named '.*chrome.*'

or

  > chrome = PS.find_processes("chrome")[0]
  > chrome.kill!

Check a process alive or not

  > chrome = PS.find_processes("chrome")[0]
  > chrome.alive?

Get all processes

  > PS.get_all_processes