sys-proctable 0.8.1-x86-linux → 0.8.2-x86-linux
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +19 -0
- data/MANIFEST +30 -38
- data/README +41 -52
- data/Rakefile +167 -0
- data/benchmarks/bench_ps.rb +21 -0
- data/doc/top.txt +4 -7
- data/examples/example_ps.rb +20 -0
- data/lib/{sys → linux/sys}/proctable.rb +3 -1
- data/lib/sys/top.rb +3 -1
- data/sys-proctable.gemspec +40 -0
- data/test/test_sys_proctable_all.rb +6 -1
- data/test/test_sys_proctable_linux.rb +1 -1
- metadata +18 -13
- data/doc/linux.txt +0 -83
data/CHANGES
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
== 0.9.0 - 14-Oct-2009
|
2
|
+
* Changed the license to Artistic 2.0.
|
3
|
+
* Fixed a bug in the OS X code where a segfault would occur when an attempt
|
4
|
+
was made to gather resource usage information on zombie processes. From
|
5
|
+
now on that information is always set to nil for zombie processes. Thanks
|
6
|
+
go to Tom Lianza for the spot and Philip Kromer for investigating the
|
7
|
+
root cause of the failure.
|
8
|
+
* Removed the FreeBSD code that read out of /proc. It was a pain from a
|
9
|
+
maintenance point of view, and most FreeBSD installs do not mount /proc
|
10
|
+
by default. The FreeBSD platform now uses the same code that the other
|
11
|
+
BSD platforms use.
|
12
|
+
* Fixed a bug in the BSD code where the ProcTable::Error class had the
|
13
|
+
wrong parent class.
|
14
|
+
* Some major gemspec updates, including an updated license. The platform
|
15
|
+
handling logic is now in the Rakefile in the 'gem' task.
|
16
|
+
* Updated the README file to include an additional acknowledgement, a
|
17
|
+
license change and some minor formatting changes.
|
18
|
+
* The test-unit library was changed from a runtime to a development dependency.
|
19
|
+
|
1
20
|
== 0.8.1 - 6-Apr-2009
|
2
21
|
* The Linux and Solaris libraries now handle the possibility of a process
|
3
22
|
terminating in the middle of a read more gracefully. If that happens, they
|
data/MANIFEST
CHANGED
@@ -1,38 +1,30 @@
|
|
1
|
-
CHANGES
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
sys-proctable.gemspec
|
6
|
-
|
7
|
-
doc/
|
8
|
-
doc/
|
9
|
-
doc/
|
10
|
-
doc/
|
11
|
-
doc/
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
ext/
|
17
|
-
ext/
|
18
|
-
ext/
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
test/
|
31
|
-
test/test_sys_proctable_darwin.rb
|
32
|
-
test/test_sys_proctable_freebsd.rb
|
33
|
-
test/test_sys_proctable_hpux.rb
|
34
|
-
test/test_sys_proctable_kvm.rb
|
35
|
-
test/test_sys_proctable_linux.rb
|
36
|
-
test/test_sys_proctable_sunos.rb
|
37
|
-
test/test_sys_proctable_windows.rb
|
38
|
-
test/test_sys_top.rb
|
1
|
+
* CHANGES
|
2
|
+
* MANIFEST
|
3
|
+
* Rakefile
|
4
|
+
* README
|
5
|
+
* sys-proctable.gemspec
|
6
|
+
* doc/bsd.txt
|
7
|
+
* doc/hpux.txt
|
8
|
+
* doc/linux.txt
|
9
|
+
* doc/solaris.txt
|
10
|
+
* doc/top.txt
|
11
|
+
* doc/windows.txt
|
12
|
+
* example/example_ps.rb
|
13
|
+
* ext/bsd/extconf.rb
|
14
|
+
* ext/bsd/sys/proctable.c
|
15
|
+
* ext/darwin/extconf.rb
|
16
|
+
* ext/darwin/sys/proctable.c
|
17
|
+
* ext/hpux/extconf.rb
|
18
|
+
* ext/hpux/sys/proctable.c
|
19
|
+
* lib/sys/top.rb
|
20
|
+
* lib/linux/sys/proctable.rb
|
21
|
+
* lib/sunos/sys/proctable.rb
|
22
|
+
* lib/windows/sys/proctable.rb
|
23
|
+
* test/test_sys_proctable_all.rb
|
24
|
+
* test/test_sys_proctable_darwin.rb
|
25
|
+
* test/test_sys_proctable_hpux.rb
|
26
|
+
* test/test_sys_proctable_bsd.rb
|
27
|
+
* test/test_sys_proctable_linux.rb
|
28
|
+
* test/test_sys_proctable_sunos.rb
|
29
|
+
* test/test_sys_proctable_windows.rb
|
30
|
+
* test/test_sys_top.rb
|
data/README
CHANGED
@@ -1,21 +1,30 @@
|
|
1
|
-
|
1
|
+
== Description
|
2
2
|
A Ruby interface for gathering process information.
|
3
3
|
|
4
|
-
|
4
|
+
== Prerequisites
|
5
5
|
* Ruby 1.8.2 or later
|
6
|
-
* Test::Unit 2.x
|
6
|
+
* Test::Unit 2.x (development only)
|
7
7
|
|
8
|
-
|
8
|
+
== Supported Platforms
|
9
9
|
* Windows NT family (NT, 2000, XP, etc)
|
10
|
-
* Linux
|
11
|
-
*
|
12
|
-
* Solaris
|
13
|
-
* HP-UX
|
14
|
-
* OS X
|
10
|
+
* Linux 2.6+
|
11
|
+
* BSD (various flavors)
|
12
|
+
* Solaris 8+
|
13
|
+
* HP-UX 10+
|
14
|
+
* OS X 10.4+
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
== Installation
|
17
|
+
=== Rubygems
|
18
|
+
gem install sys-proctable
|
19
|
+
|
20
|
+
You may need to specify a platform in some cases. For example:
|
21
|
+
|
22
|
+
gem install sys-proctable --platform mswin32 # Windows
|
23
|
+
gem install sys-proctable --platform sunos # Solaris
|
24
|
+
gem install sys-proctalbe --platform linux # Linux
|
25
|
+
|
26
|
+
=== Standard
|
27
|
+
rake install
|
19
28
|
|
20
29
|
= Synopsis
|
21
30
|
require 'sys/proctable'
|
@@ -43,24 +52,14 @@
|
|
43
52
|
...
|
44
53
|
end
|
45
54
|
|
46
|
-
|
55
|
+
== Notes
|
47
56
|
Windows users may pass a host name as a second argument to get process
|
48
57
|
information from a different host. This relies on the WMI service running.
|
49
58
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
=== FreeBSD
|
55
|
-
If you're building on FreeBSD, a standard /proc filesystem read approach is
|
56
|
-
used if mounted. Otherwise, a kvm interface is used. There are more fields
|
57
|
-
available with the kvm interface, but keep in mind that you need to be a
|
58
|
-
member of the kvm group (or root) to use this. You can tweak the extconf.rb
|
59
|
-
file manually if you want to force the issue.
|
60
|
-
|
61
|
-
=== OpenBSD, NetBSD
|
62
|
-
This library will attempt to use the kvm interface. It is untested,
|
63
|
-
however.
|
59
|
+
== Known Issues
|
60
|
+
=== BSD
|
61
|
+
A kvm interface is used. That means the owner of the process using the
|
62
|
+
sys-proctable library needs to be a member of the kvm group (or root).
|
64
63
|
|
65
64
|
=== Solaris
|
66
65
|
The cmdline member on Solaris is limited to 80 characters unless you (or
|
@@ -75,27 +74,19 @@
|
|
75
74
|
Proc::ProcessTable module. You can find that module on CPAN. Point your
|
76
75
|
browser at http://search.cpan.org.
|
77
76
|
|
78
|
-
=== Misc
|
79
|
-
If you build your library as a C extension (which is what will happen if
|
80
|
-
you run the 'build', 'test', or 'install' Rake tasks), then the .rb files
|
81
|
-
file under 'lib/sys/' are renamed to '.orig', except top.rb. This is
|
82
|
-
necessary to prevent mkmf from installing them during a 'make install'.
|
83
|
-
|
84
|
-
The 'clean' Rake task will rename them back to '.rb'.
|
85
|
-
|
86
77
|
=== Thread Safety
|
87
|
-
I am not currently using a thread-safe version of readdir().
|
88
|
-
especially concerned about it either.
|
78
|
+
I am not currently using a thread-safe version of readdir(). I am not
|
79
|
+
especially concerned about it either. If you are trying to read information
|
89
80
|
out of /proc from different threads at the same time there is something
|
90
81
|
seriously wrong with your code logic. Using readdir_r() still won't solve
|
91
82
|
all potential thread safety issues anyway.
|
92
83
|
|
93
|
-
|
84
|
+
== Future Plans
|
94
85
|
Research has indicated that the kvm approach is less favored than a sysctl
|
95
86
|
approach on BSD variants. I will try to add this interface in a future
|
96
87
|
release.
|
97
88
|
|
98
|
-
|
89
|
+
== Acknowledgements
|
99
90
|
This library is largely based on the Perl module Proc::ProcessTable by
|
100
91
|
Dan Urist. Many ideas, as well as large chunks of code, were taken
|
101
92
|
from his work. So, a big THANK YOU goes out to Dan Urist.
|
@@ -109,29 +100,27 @@
|
|
109
100
|
Thanks go to James Hranicky for providing a patch that grabs name, eid,
|
110
101
|
euid, gid and guid info in the Linux version, along with some general
|
111
102
|
debugging help.
|
103
|
+
|
104
|
+
Thanks go to David Felstead for the original OS X code.
|
112
105
|
|
113
106
|
Finally I'd like to thank all the folks who have submitted bug reports
|
114
107
|
and/or patches.
|
115
108
|
|
116
|
-
|
117
|
-
I do not have access to all platforms.
|
118
|
-
|
119
|
-
|
120
|
-
for your particular platform or give me an account on your platform so I can
|
121
|
-
develop on it.
|
109
|
+
== Help Wanted
|
110
|
+
I do not have access to all platforms. If your platform is not supported
|
111
|
+
then you will need to either submit a patch or give me a remote account
|
112
|
+
on a box with a compiler so that I can write the code.
|
122
113
|
|
123
|
-
|
114
|
+
== More documentation
|
124
115
|
See the documentation under the 'doc' directory for more information,
|
125
116
|
including platform specific notes and issues.
|
126
117
|
|
127
|
-
|
128
|
-
|
118
|
+
== License
|
119
|
+
Artistic 2.0
|
129
120
|
|
130
|
-
|
121
|
+
== Copyright
|
131
122
|
(C) 2003-2009 Daniel J. Berger
|
132
123
|
All Rights Reserved.
|
133
124
|
|
134
|
-
|
125
|
+
== Author
|
135
126
|
Daniel J. Berger
|
136
|
-
djberg96 at nospam at gmail dot com
|
137
|
-
imperator on IRC (Freenode)
|
data/Rakefile
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/clean'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'rbconfig'
|
5
|
+
|
6
|
+
desc 'Clean the build files for C versions of sys-proctable'
|
7
|
+
task :clean do
|
8
|
+
rm_rf('.test-result') if File.exists?('.test-result')
|
9
|
+
Dir['*.gem'].each{ |f| File.delete(f) }
|
10
|
+
|
11
|
+
case Config::CONFIG['host_os']
|
12
|
+
when /bsd/i
|
13
|
+
dir = 'ext/bsd'
|
14
|
+
when /darwin/i
|
15
|
+
dir = 'ext/darwin'
|
16
|
+
when /hpux/i
|
17
|
+
dir = 'ext/hpux'
|
18
|
+
end
|
19
|
+
|
20
|
+
unless Config::CONFIG['host_os'] =~ /win32|mswin|dos|cygwin|mingw|linux|sunos|solaris/i
|
21
|
+
Dir.chdir(dir) do
|
22
|
+
if Dir['*.o'].length > 0
|
23
|
+
sh 'make distclean'
|
24
|
+
Dir['sys/proctable.*'].each{ |f| rm(f) if File.extname(f) != '.c' }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'Build the sys-proctable library for C versions of sys-proctable'
|
31
|
+
task :build => [:clean] do
|
32
|
+
case Config::CONFIG['host_os']
|
33
|
+
when /bsd/i
|
34
|
+
dir = 'ext/bsd'
|
35
|
+
when /darwin/i
|
36
|
+
dir = 'ext/darwin'
|
37
|
+
when /hpux/i
|
38
|
+
dir = 'ext/hpux'
|
39
|
+
end
|
40
|
+
|
41
|
+
unless Config::CONFIG['host_os'] =~ /win32|mswin|dos|cygwin|mingw|linux|sunos|solaris/i
|
42
|
+
Dir.chdir(dir) do
|
43
|
+
ruby 'extconf.rb'
|
44
|
+
sh 'make'
|
45
|
+
cp 'proctable.' + Config::CONFIG['DLEXT'], 'sys'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
desc 'Install the sys-proctable library'
|
51
|
+
task :install => [:build] do
|
52
|
+
file = nil
|
53
|
+
dir = File.join(Config::CONFIG['sitelibdir'], 'sys')
|
54
|
+
|
55
|
+
Dir.mkdir(dir) unless File.exists?(dir)
|
56
|
+
|
57
|
+
case Config::CONFIG['host_os']
|
58
|
+
when /mswin|win32|msdos|cygwin|mingw/i
|
59
|
+
file = 'lib/windows/sys/proctable.rb'
|
60
|
+
when /linux/i
|
61
|
+
file = 'lib/linux/sys/proctable.rb'
|
62
|
+
when /sunos|solaris/i
|
63
|
+
file = 'lib/sunos/sys/proctable.rb'
|
64
|
+
when /bsd/i
|
65
|
+
Dir.chdir('ext/bsd'){ sh 'make install' }
|
66
|
+
when /darwin/i
|
67
|
+
Dir.chdir('ext/darwin'){ sh 'make install' }
|
68
|
+
when /hpux/i
|
69
|
+
Dir.chdir('ext/hpux'){ sh 'make install' }
|
70
|
+
end
|
71
|
+
|
72
|
+
cp(file, dir, :verbose => true) if file
|
73
|
+
end
|
74
|
+
|
75
|
+
desc 'Uninstall the sys-proctable library'
|
76
|
+
task :uninstall do
|
77
|
+
case Config::CONFIG['host_os']
|
78
|
+
when /win32|mswin|dos|cygwin|mingw|linux|sunos|solaris/i
|
79
|
+
dir = File.join(Config::CONFIG['sitelibdir'], 'sys')
|
80
|
+
file = File.join(dir, 'proctable.rb')
|
81
|
+
else
|
82
|
+
dir = File.join(Config::CONFIG['sitearchdir'], 'sys')
|
83
|
+
file = File.join(dir, 'proctable.' + Config::CONFIG['DLEXT'])
|
84
|
+
end
|
85
|
+
|
86
|
+
rm(file)
|
87
|
+
end
|
88
|
+
|
89
|
+
desc 'Run the benchmark suite'
|
90
|
+
task :bench => [:build] do
|
91
|
+
sh "ruby -Ilib benchmarks/bench_ps.rb"
|
92
|
+
end
|
93
|
+
|
94
|
+
desc 'Run the example program'
|
95
|
+
task :example => [:build] do
|
96
|
+
sh 'ruby -Ilib -Iext examples/example_ps.rb'
|
97
|
+
end
|
98
|
+
|
99
|
+
desc 'Run the test suite'
|
100
|
+
Rake::TestTask.new do |t|
|
101
|
+
task :test => :build
|
102
|
+
t.libs << 'test'
|
103
|
+
|
104
|
+
case Config::CONFIG['host_os']
|
105
|
+
when /mswin|msdos|cygwin|mingw/i
|
106
|
+
t.test_files = FileList['test/test_sys_proctable_windows.rb']
|
107
|
+
t.libs << 'lib/windows'
|
108
|
+
when /linux/i
|
109
|
+
t.test_files = FileList['test/test_sys_proctable_linux.rb']
|
110
|
+
t.libs << 'lib/linux'
|
111
|
+
when /sunos|solaris/i
|
112
|
+
t.test_files = FileList['test/test_sys_proctable_sunos.rb']
|
113
|
+
t.libs << 'lib/sunos'
|
114
|
+
when /darwin/i
|
115
|
+
t.libs << 'ext/darwin'
|
116
|
+
t.test_files = FileList['test/test_sys_proctable_darwin.rb']
|
117
|
+
when /bsd/i
|
118
|
+
t.libs << 'ext/bsd'
|
119
|
+
t.test_files = FileList['test/test_sys_proctable_bsd.rb']
|
120
|
+
when /hpux/i
|
121
|
+
t.libs << 'ext/hpux'
|
122
|
+
t.test_files = FileList['test/test_sys_proctable_hpux.rb']
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
desc 'Create a gem'
|
127
|
+
task :gem do
|
128
|
+
spec = eval(IO.read('sys-proctable.gemspec'))
|
129
|
+
|
130
|
+
case Config::CONFIG['host_os']
|
131
|
+
when /bsd/i
|
132
|
+
spec.files << 'ext/bsd/sys/proctable.c'
|
133
|
+
spec.extra_rdoc_files << 'ext/bsd/sys/proctable.c'
|
134
|
+
spec.test_files << 'test/test_sys_proctable_bsd.rb'
|
135
|
+
spec.extensions = ['ext/bsd/extconf.rb']
|
136
|
+
when /darwin/i
|
137
|
+
spec.files << 'ext/darwin/sys/proctable.c'
|
138
|
+
spec.extra_rdoc_files << 'ext/darwin/sys/proctable.c'
|
139
|
+
spec.test_files << 'test/test_sys_proctable_darwin.rb'
|
140
|
+
spec.extensions = ['ext/darwin/extconf.rb']
|
141
|
+
when /hpux/i
|
142
|
+
spec.files << 'ext/hpux/sys/proctable.c'
|
143
|
+
spec.extra_rdoc_files << 'ext/hpux/sys/proctable.c'
|
144
|
+
spec.test_files << 'test/test_sys_proctable_hpux.rb'
|
145
|
+
spec.extensions = ['ext/hpux/extconf.rb']
|
146
|
+
when /linux/i
|
147
|
+
spec.require_paths = ['lib', 'lib/linux']
|
148
|
+
spec.files += ['lib/linux/sys/proctable.rb']
|
149
|
+
spec.test_files << 'test/test_sys_proctable_linux.rb'
|
150
|
+
when /sunos|solaris/i
|
151
|
+
spec.require_paths = ['lib', 'lib/sunos']
|
152
|
+
spec.files += ['lib/sunos/sys/proctable.rb']
|
153
|
+
spec.test_files << 'test/test_sys_proctable_sunos.rb'
|
154
|
+
when /mswin|win32|dos|cygwin|mingw/i
|
155
|
+
spec.require_paths = ['lib', 'lib/windows']
|
156
|
+
spec.files += ['lib/windows/sys/proctable.rb']
|
157
|
+
spec.test_files << 'test/test_sys_proctable_windows.rb'
|
158
|
+
end
|
159
|
+
|
160
|
+
Gem::Builder.new(spec).build
|
161
|
+
end
|
162
|
+
|
163
|
+
desc 'Install the sys-proctable library as a gem'
|
164
|
+
task :install_gem => [:gem] do
|
165
|
+
gem_name = Dir['*.gem'].first
|
166
|
+
sh "gem install #{gem_name}"
|
167
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
########################################################################
|
2
|
+
# bench_ps.rb
|
3
|
+
#
|
4
|
+
# Benchmark program to show overall speed and compare the block form
|
5
|
+
# versus the non-block form. You should run this benchmark via the
|
6
|
+
# 'rake bench' Rake task.
|
7
|
+
########################################################################
|
8
|
+
require 'benchmark'
|
9
|
+
require 'sys/proctable'
|
10
|
+
|
11
|
+
MAX = 10
|
12
|
+
|
13
|
+
Benchmark.bm do |bench|
|
14
|
+
bench.report("Block form"){
|
15
|
+
MAX.times{ Sys::ProcTable.ps{} }
|
16
|
+
}
|
17
|
+
|
18
|
+
bench.report("Non-block form"){
|
19
|
+
MAX.times{ Sys::ProcTable.ps }
|
20
|
+
}
|
21
|
+
end
|
data/doc/top.txt
CHANGED
@@ -7,9 +7,8 @@
|
|
7
7
|
|
8
8
|
= Synopsis
|
9
9
|
require "sys/top"
|
10
|
-
include Sys
|
11
10
|
|
12
|
-
Top.top(5).each{ |ps|
|
11
|
+
Sys::Top.top(5).each{ |ps|
|
13
12
|
p ps
|
14
13
|
}
|
15
14
|
|
@@ -18,7 +17,7 @@ VERSION
|
|
18
17
|
Returns the version number of this package as a String.
|
19
18
|
|
20
19
|
= Class Methods
|
21
|
-
Top.top(number=10, field="pctcpu")
|
20
|
+
Sys::Top.top(number=10, field="pctcpu")
|
22
21
|
Returns an array of ProcTableStruct's. The size of the array (i.e. the
|
23
22
|
number of processes) that it returns is based on +number+, and sorted by
|
24
23
|
+pctcpu+. By default, the size and field values are 10 and "pctcpu",
|
@@ -33,7 +32,7 @@ Top.top(number=10, field="pctcpu")
|
|
33
32
|
http://www.rubyforge.org/projects/sysutils
|
34
33
|
|
35
34
|
= License
|
36
|
-
|
35
|
+
Artistic 2.0
|
37
36
|
|
38
37
|
= Copyright
|
39
38
|
(C) 2004-2009 Daniel J. Berger
|
@@ -45,6 +44,4 @@ Top.top(number=10, field="pctcpu")
|
|
45
44
|
warranties of merchantability and fitness for a particular purpose.
|
46
45
|
|
47
46
|
= Author
|
48
|
-
Daniel J. Berger
|
49
|
-
djberg96 at nospam at gmail dot com
|
50
|
-
imperator on IRC (Freenode)
|
47
|
+
Daniel J. Berger
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#######################################################################
|
2
|
+
# example_ps.rb
|
3
|
+
#
|
4
|
+
# Generic test program that demonstrates the use of ProcTable.ps. You
|
5
|
+
# can run this via the 'rake example' task.
|
6
|
+
#
|
7
|
+
# Modify as you see fit
|
8
|
+
#######################################################################
|
9
|
+
require 'sys/proctable'
|
10
|
+
include Sys
|
11
|
+
|
12
|
+
puts "VERSION: " + ProcTable::VERSION
|
13
|
+
sleep 2
|
14
|
+
|
15
|
+
ProcTable.ps{ |s|
|
16
|
+
ProcTable.fields.each{ |field|
|
17
|
+
puts "#{field}: " + s.send(field).to_s
|
18
|
+
}
|
19
|
+
puts '=' * 30
|
20
|
+
}
|
@@ -3,12 +3,14 @@ module Sys
|
|
3
3
|
|
4
4
|
# The ProcTable class encapsulates process table information.
|
5
5
|
class ProcTable
|
6
|
+
|
7
|
+
class Error < StandardError; end
|
6
8
|
|
7
9
|
# There is no constructor
|
8
10
|
private_class_method :new
|
9
11
|
|
10
12
|
# The version of the sys-proctable library
|
11
|
-
VERSION = '0.
|
13
|
+
VERSION = '0.9.0'
|
12
14
|
|
13
15
|
private
|
14
16
|
|
data/lib/sys/top.rb
CHANGED
@@ -18,9 +18,11 @@ module Sys
|
|
18
18
|
#
|
19
19
|
def self.top(num=10, field='pctcpu')
|
20
20
|
field = field.to_s if field.is_a?(Symbol)
|
21
|
+
|
22
|
+
windows = /mswin|win32|dos|cygwin|mingw/i
|
21
23
|
|
22
24
|
# Sort by pid on Windows by default
|
23
|
-
if Config::CONFIG['host_os'].match(
|
25
|
+
if Config::CONFIG['host_os'].match(windows) && field == 'pctcpu'
|
24
26
|
field = 'pid'
|
25
27
|
end
|
26
28
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rbconfig'
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = 'sys-proctable'
|
6
|
+
gem.version = '0.8.2'
|
7
|
+
gem.author = 'Daniel J. Berger'
|
8
|
+
gem.license = 'Artistic 2.0'
|
9
|
+
gem.email = 'djberg96@gmail.com'
|
10
|
+
gem.homepage = 'http://www.rubyforge.org/projects/sysutils'
|
11
|
+
gem.platform = Gem::Platform::CURRENT
|
12
|
+
gem.summary = 'An interface for providing process table information'
|
13
|
+
gem.has_rdoc = true
|
14
|
+
gem.test_files = ['test/test_sys_proctable_all.rb']
|
15
|
+
|
16
|
+
# Additional files for your platform are added by the 'rake gem' task.
|
17
|
+
gem.files = [
|
18
|
+
'benchmarks/bench_ps.rb',
|
19
|
+
'examples/example_ps.rb',
|
20
|
+
'lib/sys/top.rb',
|
21
|
+
'CHANGES',
|
22
|
+
'MANIFEST',
|
23
|
+
'Rakefile',
|
24
|
+
'README',
|
25
|
+
'sys-proctable.gemspec'
|
26
|
+
]
|
27
|
+
|
28
|
+
gem.rubyforge_project = 'sysutils'
|
29
|
+
gem.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST', 'doc/top.txt']
|
30
|
+
|
31
|
+
gem.add_development_dependency('test-unit', '>= 2.0.3')
|
32
|
+
|
33
|
+
gem.description = <<-EOF
|
34
|
+
The sys-proctable library provides an interface for gathering information
|
35
|
+
about processes on your system, i.e. the process table. Most major
|
36
|
+
platforms are supported and, while different platforms may return
|
37
|
+
different information, the external interface is identical across
|
38
|
+
platforms.
|
39
|
+
EOF
|
40
|
+
end
|
@@ -23,7 +23,7 @@ class TC_ProcTable_All < Test::Unit::TestCase
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_version
|
26
|
-
assert_equal('0.
|
26
|
+
assert_equal('0.9.0', ProcTable::VERSION)
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_fields
|
@@ -69,6 +69,11 @@ class TC_ProcTable_All < Test::Unit::TestCase
|
|
69
69
|
def test_new_not_allowed
|
70
70
|
assert_raise(NoMethodError){ Sys::ProcTable.new }
|
71
71
|
end
|
72
|
+
|
73
|
+
def test_error_class_defined
|
74
|
+
assert_not_nil(Sys::ProcTable::Error)
|
75
|
+
assert_kind_of(StandardError, Sys::ProcTable::Error.new)
|
76
|
+
end
|
72
77
|
|
73
78
|
def teardown
|
74
79
|
@pid = nil
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sys-proctable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: x86-linux
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
@@ -9,20 +9,20 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-04-23 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: test-unit
|
17
|
-
type: :
|
17
|
+
type: :development
|
18
18
|
version_requirement:
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 2.0.
|
23
|
+
version: 2.0.3
|
24
24
|
version:
|
25
|
-
description:
|
25
|
+
description: " The sys-proctable library provides an interface for gathering information\n about processes on your system, i.e. the process table. Most major\n platforms are supported and, while different platforms may return\n different information, the external interface is identical across\n platforms.\n"
|
26
26
|
email: djberg96@gmail.com
|
27
27
|
executables: []
|
28
28
|
|
@@ -33,28 +33,33 @@ extra_rdoc_files:
|
|
33
33
|
- README
|
34
34
|
- MANIFEST
|
35
35
|
- doc/top.txt
|
36
|
-
- doc/linux.txt
|
37
36
|
files:
|
37
|
+
- benchmarks/bench_ps.rb
|
38
|
+
- examples/example_ps.rb
|
38
39
|
- lib/sys/top.rb
|
39
|
-
- test/test_sys_proctable_all.rb
|
40
40
|
- CHANGES
|
41
|
-
- README
|
42
41
|
- MANIFEST
|
42
|
+
- Rakefile
|
43
|
+
- README
|
44
|
+
- sys-proctable.gemspec
|
45
|
+
- test/test_sys_proctable_all.rb
|
43
46
|
- doc/top.txt
|
44
|
-
- lib/sys/proctable.rb
|
45
|
-
- doc/linux.txt
|
47
|
+
- lib/linux/sys/proctable.rb
|
46
48
|
has_rdoc: true
|
47
49
|
homepage: http://www.rubyforge.org/projects/sysutils
|
50
|
+
licenses:
|
51
|
+
- Artistic 2.0
|
48
52
|
post_install_message:
|
49
53
|
rdoc_options: []
|
50
54
|
|
51
55
|
require_paths:
|
52
56
|
- lib
|
57
|
+
- lib/linux
|
53
58
|
required_ruby_version: !ruby/object:Gem::Requirement
|
54
59
|
requirements:
|
55
60
|
- - ">="
|
56
61
|
- !ruby/object:Gem::Version
|
57
|
-
version:
|
62
|
+
version: "0"
|
58
63
|
version:
|
59
64
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
65
|
requirements:
|
@@ -65,9 +70,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
70
|
requirements: []
|
66
71
|
|
67
72
|
rubyforge_project: sysutils
|
68
|
-
rubygems_version: 1.3.
|
73
|
+
rubygems_version: 1.3.3
|
69
74
|
signing_key:
|
70
|
-
specification_version:
|
75
|
+
specification_version: 3
|
71
76
|
summary: An interface for providing process table information
|
72
77
|
test_files:
|
73
78
|
- test/test_sys_proctable_all.rb
|
data/doc/linux.txt
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
= Description
|
2
|
-
A Ruby interface for gathering process table information. This is a pure
|
3
|
-
Ruby implementation that reads data out of your /proc filesystem.
|
4
|
-
|
5
|
-
= Synopsis
|
6
|
-
require 'sys/proctable'
|
7
|
-
include Sys
|
8
|
-
|
9
|
-
# Everything
|
10
|
-
ProcTable.ps{ |p|
|
11
|
-
puts p.pid.to_s
|
12
|
-
puts p.comm
|
13
|
-
...
|
14
|
-
}
|
15
|
-
|
16
|
-
or
|
17
|
-
|
18
|
-
# Just one process
|
19
|
-
p = ProcTable.ps(2123)
|
20
|
-
puts p.pid.to_s
|
21
|
-
puts p.comm
|
22
|
-
...
|
23
|
-
|
24
|
-
or
|
25
|
-
|
26
|
-
# Return the results as an array of ProcTableStructs
|
27
|
-
a = ProcTable.ps()
|
28
|
-
a.each do |p|
|
29
|
-
puts a.pid
|
30
|
-
...
|
31
|
-
end
|
32
|
-
|
33
|
-
= Constants
|
34
|
-
VERSION
|
35
|
-
Returns the current version number for this package (as a string).
|
36
|
-
|
37
|
-
= Class Methods
|
38
|
-
ProcTable.fields
|
39
|
-
Returns an array of fields available on the current OS.
|
40
|
-
|
41
|
-
ProcTable.ps(pid=nil)
|
42
|
-
ProcTable.ps{ |s| ... }
|
43
|
-
If no pid's or processes are included as arguments, in block form it
|
44
|
-
returns a struct of type ProcTableStruct for every process in the proc
|
45
|
-
table. Otherwise it returns an array of ProcTableStruct's.
|
46
|
-
|
47
|
-
If a process id is provided, a single ProcTable struct is returned, or
|
48
|
-
nil if the pid is not found.
|
49
|
-
|
50
|
-
= Exception Classes
|
51
|
-
ProcTable::Error < StandardError
|
52
|
-
Raised if the /proc field is unreadable and/or unmounted.
|
53
|
-
|
54
|
-
= Supported fields
|
55
|
-
You can view the supported fields with the "fields()" class method.
|
56
|
-
|
57
|
-
= Future Plans
|
58
|
-
None at this time. Please post any feature requests on the project page
|
59
|
-
at http://www.rubyforge.org/projects/sysutils.
|
60
|
-
|
61
|
-
= Known Bugs
|
62
|
-
None known. Please log any bugs on the project page at
|
63
|
-
http://www.rubyforge.org/projects/sysutils
|
64
|
-
|
65
|
-
= License
|
66
|
-
Ruby's
|
67
|
-
|
68
|
-
= Copyright
|
69
|
-
(C) 2003-2009 Daniel J. Berger
|
70
|
-
All Rights Reserved
|
71
|
-
|
72
|
-
= Warranty
|
73
|
-
This package is provided "as is" and without any express or
|
74
|
-
implied warranties, including, without limitation, the implied
|
75
|
-
warranties of merchantability and fitness for a particular purpose.
|
76
|
-
|
77
|
-
= Author
|
78
|
-
Daniel J. Berger
|
79
|
-
djberg96 at nospam at gmail dot com
|
80
|
-
imperator on IRC (Freenode)
|
81
|
-
|
82
|
-
= See Also
|
83
|
-
ps, proc(5)
|