ps-ruby 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0ca66f32f6eca7fd6e96a2b7fb033f7bda48a19
4
- data.tar.gz: f82c63cfe8d729ba672ea791fa52878e64a0bbba
3
+ metadata.gz: 6cde97732e5357bccc4bdada592dbbd33414e612
4
+ data.tar.gz: 45c14906dfaa1d33cacae177df2d0483cac6df00
5
5
  SHA512:
6
- metadata.gz: 1113ff303d2d5d39d606defdbd348a77bd0bd0403909699951358d1ac631b4042e5d216eb29e0339ec0bf631ee3d10433b01fdeb2580565f62011ca2621623e7
7
- data.tar.gz: 875aef0cabdb82957b6004e971f0708235850cc55428d9703ce6df322ddee8c0f36781e3087fa3b8f0ec8d31dea7b8c33afa41aa9529ffcd45c66a2e03afe8c2
6
+ metadata.gz: 28dd310b606ce739a3c9c1adbf04e457826b785f187745c34209bc50cdcc63a2a863e027c19342863afa644f7227f1acd3d358540461425b0aa3f25d5633d32f
7
+ data.tar.gz: 35aa1030b27f84b4ea479aefd46cf48a4cdb06bbf9270de548562a121b7838353780d8b47111b95934725ff1f600be3f67eba3d067d9cf12aaa3d29c1f6dbf33
@@ -1,10 +1,22 @@
1
1
 
2
2
  require File.join(File.expand_path(File.dirname(__FILE__)), "../lib/ps-ruby.rb")
3
3
 
4
+ # list `ps aux` attrs
4
5
  puts PS.attrs.to_s
5
- puts PS.find_process("zsh").to_s
6
6
 
7
+ # display a simple table
8
+ PS.find_processes("zsh").simple_display
7
9
 
8
- # PS.simple_display(/.*zsh.*/i)
9
- # PS.simple_display("chrome")
10
- # PS.simple_display
10
+ # find by special attrs
11
+ put PS.find_processes("PID", PROCESS_ID)
12
+
13
+ # Kill all process named 'irb'
14
+ # PS.find_processes("irb").kill!
15
+
16
+ # check a process is alive or not
17
+ PS.find_processes("chrome").first.alive?
18
+
19
+ # chaining select
20
+ ms = PS.find_processes("Microsoft")
21
+ word = ms.find_processes("Word")
22
+ ppt = ms.find_processes("PowerPoint")
Binary file
@@ -34,11 +34,11 @@ class PsProcessList < Array
34
34
  nil
35
35
  end
36
36
 
37
- def find_process(name)
38
- find_process_by("COMMAND", name)
37
+ def find_processes(name)
38
+ find_processes_by("COMMAND", name)
39
39
  end
40
40
 
41
- def find_process_by(attr_name, value)
41
+ def find_processes_by(attr_name, value)
42
42
  regex = if value.class != Regexp then Regexp.new(".*#{value}.*", Regexp::IGNORECASE) else value end
43
43
  PsProcessList.new(self.select{|x| x[attr_name] =~ regex })
44
44
  end
@@ -56,15 +56,15 @@ module PS
56
56
  module_function
57
57
 
58
58
  def simple_display(name = "", limit_process_name_len=30)
59
- find_process(name).simple_display(limit_process_name_len)
59
+ find_processes(name).simple_display(limit_process_name_len)
60
60
  end
61
61
 
62
- def find_process(name)
63
- find_process_by("COMMAND", name)
62
+ def find_processes(name)
63
+ find_processes_by("COMMAND", name)
64
64
  end
65
65
 
66
- def find_process_by(attr_name, value)
67
- get_all_processes.find_process_by(attr_name, value)
66
+ def find_processes_by(attr_name, value)
67
+ get_all_processes.find_processes_by(attr_name, value)
68
68
  end
69
69
 
70
70
  def attrs
@@ -2,6 +2,6 @@ module PS
2
2
  module_function
3
3
 
4
4
  def VERSION
5
- "0.0.2"
5
+ "0.0.3"
6
6
  end
7
7
  end
data/readme.md CHANGED
@@ -27,7 +27,7 @@ PS-Ruby is a simple ps wrapper with ruby. You can see [example.rb](example/examp
27
27
  ...
28
28
  ```
29
29
 
30
- ## Display special process by name
30
+ ## Display special processes by name
31
31
 
32
32
  ```ruby
33
33
  > PS.simple_display("zsh")
@@ -42,7 +42,7 @@ or
42
42
  or
43
43
 
44
44
  ```ruby
45
- PS.find_process("zsh").simple_display
45
+ PS.find_processes("zsh").simple_display
46
46
  ```
47
47
 
48
48
  ```
@@ -52,11 +52,11 @@ or
52
52
  83005 0.0 0.0 -zsh
53
53
  ```
54
54
 
55
- ## Get special process by name
55
+ ## Get special processes by name
56
56
 
57
57
 
58
58
  ```ruby
59
- > PS.find_process("zsh")
59
+ > PS.find_processes("zsh")
60
60
  ```
61
61
 
62
62
  ```ruby
@@ -102,10 +102,10 @@ or
102
102
  ## Chaining
103
103
 
104
104
  ```ruby
105
- > PS.find_process("zsh").find_process_by("PID", "67468")
105
+ > PS.find_processes("zsh").find_process_by("PID", "67468")
106
106
  ```
107
107
 
108
- ```
108
+ ```ruby
109
109
  [{
110
110
  "USER" => "HondaDai",
111
111
  "PID" => "67468",
@@ -121,24 +121,36 @@ or
121
121
  }]
122
122
  ```
123
123
 
124
+ ```ruby
125
+ ms = PS.find_processes("Microsoft")
126
+ word = ms.find_processes("Word")
127
+ ppt = ms.find_processes("PowerPoint")
128
+ ```
129
+
130
+ ## Get special attribute
131
+
132
+ ```ruby
133
+ commands = PS.find_processes("Microsoft").pick_by_attr("COMMAND")
134
+ ```
135
+
124
136
  ## Kill process
125
137
 
126
138
  ```ruby
127
- > PS.find_process("chrome").kill! # kill all processes named '.*chrome.*'
139
+ > PS.find_processes("chrome").kill! # kill all processes named '.*chrome.*'
128
140
  ```
129
141
 
130
142
  or
131
143
 
132
144
  ```ruby
133
- > chrome = PS.find_process("chrome")[0]
145
+ > chrome = PS.find_processes("chrome")[0]
134
146
  > chrome.kill!
135
147
  ```
136
148
 
137
149
 
138
- ## Check process alive
150
+ ## Check a process alive or not
139
151
 
140
152
  ```ruby
141
- > chrome = PS.find_process("chrome")[0]
153
+ > chrome = PS.find_processes("chrome")[0]
142
154
  > chrome.alive?
143
155
  ```
144
156
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ps-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - HondaDai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-16 00:00:00.000000000 Z
11
+ date: 2015-04-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -23,10 +23,11 @@ files:
23
23
  - LICENSE.txt
24
24
  - Rakefile
25
25
  - example/example.rb
26
+ - gem/ps-ruby-0.0.1.gem
27
+ - gem/ps-ruby-0.0.2.gem
26
28
  - lib/ps-ruby.rb
27
29
  - lib/ps-ruby/ps-ruby.rb
28
30
  - lib/ps-ruby/version.rb
29
- - ps-ruby-0.0.1.gem
30
31
  - ps-ruby.gemspec
31
32
  - readme.md
32
33
  homepage: https://github.com/HondaDai/ps-ruby