ps_grep 0.0.1

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.
Files changed (3) hide show
  1. data/bin/ps_grep +0 -0
  2. data/lib/ps_grep.rb +69 -0
  3. metadata +68 -0
data/bin/ps_grep ADDED
File without changes
data/lib/ps_grep.rb ADDED
@@ -0,0 +1,69 @@
1
+ # ps_grep
2
+ # Find a process using name pattern
3
+ # Author: Jackie.ju@gmail.com
4
+ #
5
+ require 'rubygems'
6
+ require 'rbconfig'
7
+
8
+ s = Config::CONFIG['target_os']
9
+ if s.index("linux")
10
+ $_OS_TYPE = "linux"
11
+ elsif s.index("darwin")
12
+ $_OS_TYPE = "darwin"
13
+ end
14
+
15
+ def find_process(*pattern)
16
+ mongrels = []
17
+
18
+ s = pattern.join(" | grep ")
19
+
20
+ command = "ps aux | grep -v grep | grep #{s}"
21
+ p "command=>#{command}"
22
+ r = `#{command}`
23
+ print "==>command output<===\n#{r}"
24
+ print "==>command output end<===\n"
25
+
26
+ if $_OS_TYPE == "linux"
27
+
28
+
29
+ r.scan(/^(.*?)\s+(\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+)\s+(\d+)\s+(.*?)\s+(.*?)\s+(.*?)\s+(\d+:\d+\.\d+)\s+(.*?)$/){|m|
30
+ mongrels.push({
31
+ :user=>m[0].strip,
32
+ :pid=>m[1],
33
+ :cpu=>m[2],
34
+ :mem1=>m[3],
35
+ :mem2=>m[4],
36
+ :mem3=>m[5],
37
+ :start=>m[8],
38
+ :time=>m[9],
39
+ :cmd=>m[10].strip
40
+ })
41
+ }
42
+ elsif $_OS_TYPE == "darwin"
43
+ r.scan(/^(.*?)\s+(\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+)\s+(\d+)\s+(.*?)\s+(.*?)\s+(.*?)\s+(\d+:\d+\.\d+)\s+(.*?)$/){|m|
44
+ mongrels.push({
45
+ :user=>m[0].strip,
46
+ :pid=>m[1],
47
+ :cpu=>m[2],
48
+ :mem1=>m[3],
49
+ :mem2=>m[4],
50
+ :mem3=>m[5],
51
+ :start=>m[8],
52
+ :time=>m[9],
53
+ :cmd=>m[10].strip
54
+ })
55
+ }
56
+ else
57
+ p "OS #{$_OS_TYPE} is not supported"
58
+ end
59
+
60
+ return mongrels
61
+ end
62
+
63
+
64
+ # test
65
+ =begin
66
+ ret = find_process("ruby", "")
67
+ p "====>"
68
+ p ret
69
+ =end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ps_grep
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Ju Weihua (Jackie Ju)
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2016-01-05 00:00:00 +08:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Find a process info by pattern!
23
+ email: jackie.ju@gmail.com
24
+ executables:
25
+ - ps_grep
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/ps_grep.rb
32
+ - bin/ps_grep
33
+ has_rdoc: true
34
+ homepage: http://rubygems.org/gems/ps_grep
35
+ licenses:
36
+ - MIT
37
+ post_install_message:
38
+ rdoc_options: []
39
+
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ hash: 3
48
+ segments:
49
+ - 0
50
+ version: "0"
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.3.7
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Find a process info by pattern!
67
+ test_files: []
68
+