rumblinthebronx-sys-proctable 0.9.5-universal-java → 0.9.6-universal-java
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/linux/sys/proctable.rb +31 -0
- data/sys-proctable.gemspec +2 -1
- metadata +18 -2
data/lib/linux/sys/proctable.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'os'
|
2
|
+
|
1
3
|
# The Sys module serves as a namespace only.
|
2
4
|
module Sys
|
3
5
|
|
@@ -78,6 +80,33 @@ module Sys
|
|
78
80
|
|
79
81
|
ProcTableStruct = Struct.new('ProcTableStruct', *@fields)
|
80
82
|
|
83
|
+
# Returns an Array of Proctable structs or just the matching one if +pid+ is given.
|
84
|
+
def self.ps_mac(process_id=nil)
|
85
|
+
output = `ps aux`
|
86
|
+
output = output.split "\n"
|
87
|
+
output.delete output.first
|
88
|
+
result = []
|
89
|
+
|
90
|
+
output.each do |process_info|
|
91
|
+
struct = ProcTableStruct.new
|
92
|
+
process_info = process_info.split " "
|
93
|
+
process_info.delete ""
|
94
|
+
user_info = `id #{process_info.first}`
|
95
|
+
/uid=((?<uid>\d*))/ =~ user_info
|
96
|
+
/gid=((?<gid>\d*))/ =~ user_info
|
97
|
+
pid = process_info[1].to_i
|
98
|
+
/[\.|\:]\d\d (?<cmdline>.*)/ =~ process_info.last
|
99
|
+
struct.pid = pid
|
100
|
+
struct.uid = uid.to_i
|
101
|
+
struct.gid = gid.to_i
|
102
|
+
struct.cmdline = cmdline
|
103
|
+
return struct if pid == process_id
|
104
|
+
result << struct
|
105
|
+
end
|
106
|
+
|
107
|
+
result
|
108
|
+
end
|
109
|
+
|
81
110
|
# In block form, yields a ProcTableStruct for each process entry that you
|
82
111
|
# have rights to. This method returns an array of ProcTableStruct's in
|
83
112
|
# non-block form.
|
@@ -102,6 +131,8 @@ module Sys
|
|
102
131
|
# either return all information for a process, or none at all.
|
103
132
|
#
|
104
133
|
def self.ps(pid=nil)
|
134
|
+
return ps_mac(pid) if OS.mac?
|
135
|
+
raise NotImplementedError unless OS.linux?
|
105
136
|
array = block_given? ? nil : []
|
106
137
|
struct = nil
|
107
138
|
|
data/sys-proctable.gemspec
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = 'rumblinthebronx-sys-proctable'
|
5
|
-
spec.version = '0.9.
|
5
|
+
spec.version = '0.9.6'
|
6
6
|
spec.author = 'Daniel J. Berger'
|
7
7
|
spec.license = 'Artistic 2.0'
|
8
8
|
spec.email = 'djberg96@gmail.com'
|
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST', 'doc/top.txt']
|
31
31
|
|
32
32
|
spec.add_development_dependency('test-unit', '>= 2.4.0')
|
33
|
+
spec.add_development_dependency('os', '>= 0.9.6')
|
33
34
|
|
34
35
|
spec.description = <<-EOF
|
35
36
|
The sys-proctable library provides an interface for gathering information
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rumblinthebronx-sys-proctable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.6
|
5
5
|
prerelease:
|
6
6
|
platform: universal-java
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: test-unit
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 2.4.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: os
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.9.6
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.9.6
|
30
46
|
description: ! " The sys-proctable library provides an interface for gathering
|
31
47
|
information\n about processes on your system, i.e. the process table. Most major\n
|
32
48
|
\ platforms are supported and, while different platforms may return\n different
|