rumblinthebronx-sys-proctable 0.9.5-universal-java

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES ADDED
@@ -0,0 +1,310 @@
1
+ == 0.9.2 - 8-Oct-2012
2
+ * Added cmdline support for OS X. Thanks go to Matthias Zirnstein for
3
+ the patch.
4
+ * Warning cleanup for 1.9.
5
+ * Updated the gem platform handling. Replaced the borked string approach
6
+ with a two element array for Gem::Platform.new.
7
+ * MS date strings are now parse with DateTime instead of Date.
8
+
9
+ == 0.9.1 - 3-Aug-2011
10
+ * Added the pctcpu and pctmem members for Linux.
11
+ * Added Errno::ESRCH to a rescue clause on Linux that fixed a bug
12
+ where a missing entry wasn't being skipped when run as root. Thanks
13
+ go to Austin Ziegler for the spot and patch.
14
+ * Fixed a build warning for Darwin.
15
+ * Updates to the test suite for both Darwin and Linux.
16
+ * Added an explicit type check for BSD for pids.
17
+ * Added nicer error messages for BSD if kvm_open fails.
18
+ * Added .core files to the clean task.
19
+ * Altered the platform settings in the Rakefile so that generated gems
20
+ use 'universal' platform architectures for any particular operating system.
21
+
22
+ == 0.9.0 - 14-Oct-2009
23
+ * Changed the license to Artistic 2.0.
24
+ * Fixed a bug in the OS X code where a segfault would occur when an attempt
25
+ was made to gather resource usage information on zombie processes. From
26
+ now on that information is always set to nil for zombie processes. Thanks
27
+ go to Tom Lianza for the spot and Philip Kromer for investigating the
28
+ root cause of the failure.
29
+ * Removed the FreeBSD code that read out of /proc. It was a pain from a
30
+ maintenance point of view, and most FreeBSD installs do not mount /proc
31
+ by default. The FreeBSD platform now uses the same code that the other
32
+ BSD platforms use.
33
+ * Fixed a bug in the BSD code where the ProcTable::Error class had the
34
+ wrong parent class.
35
+ * Some major gemspec updates, including an updated license. The platform
36
+ handling logic is now in the Rakefile in the 'gem' task.
37
+ * Updated the README file to include an additional acknowledgement, a
38
+ license change and some minor formatting changes.
39
+ * The test-unit library was changed from a runtime to a development dependency.
40
+
41
+ == 0.8.1 - 6-Apr-2009
42
+ * The Linux and Solaris libraries now handle the possibility of a process
43
+ terminating in the middle of a read more gracefully. If that happens, they
44
+ merely skip to the next record, i.e. it's all or nothing. Thanks go to
45
+ Heejong Lee for the spot and patch.
46
+ * Fixed a bug in the Linux version where embedded nulls were not being
47
+ stripped out of the cmdline data.
48
+ * Added the comm alias back to the Solaris version. Thanks go to Jun Young Kim
49
+ for the spot.
50
+
51
+ == 0.8.0 - 26-Jan-2009
52
+ * The Linux and Solaris versions of this library are now pure Ruby. Be warned,
53
+ however, that only Solaris 8 and later are now supported. This may change
54
+ in a future release if there's demand to support 2.6 and 2.7.
55
+ * Some Struct::ProcTableStruct members have changed. As a general rule they
56
+ now more closely match the C struct member name. See individual platforms
57
+ for more details.
58
+ * Bug fix for the cmd_args struct member on Solaris.
59
+ * Bug fixes for OS X. Added a VERSION constant, fixed struct name, and changed
60
+ pct_cpu to pctcpu.
61
+ * The .new method is now explicitly illegal.
62
+ * The Struct::ProcTableStruct instances are now frozen. This is read-only data.
63
+ * Added the peak_page_file_usage and status members on MS Windows. The status
64
+ member is always nil, but was added for completeness.
65
+ * Fixed the quota_peak_paged_pool_usage member on MS Windows.
66
+ * ProcTableError is now ProcTable::Error.
67
+ * Minor test case fix for kvm/bsd based versions.
68
+ * Added the 'time' library as a require for Windows (to parse MS date/time
69
+ format strings).
70
+ * The kvm (bsd.c) implementation now works for FreeBSD 7.
71
+ * Added many more tests.
72
+ * Added some benchmarking code in the 'benchmarks' directory.
73
+ * Added a 'bench' Rake task.
74
+ * Renamed the test_ps.rb file to example_ps.rb in order to avoid any possible
75
+ confusion with actual test files.
76
+ * Added an 'example' rake task to run the example file.
77
+
78
+ == 0.7.6 - 11-Jul-2007
79
+ * Fixed the starttime for Linux. Thanks go to Yaroslav Dmitriev for the spot.
80
+ * Fixed a bug in the MS Windows version within a private method that parsed
81
+ an MS specific date format. This was caused by a backwards incompatible
82
+ change in the Time.parse method in Ruby 1.8.6. See ruby-core: 11245 ff.
83
+ * Fixed the gemspec (I hope). Please let me know if you have problems.
84
+ * Added a Rakefile. Building, testing and installing should now be handled via
85
+ Rake tasks. The install.rb file has been removed - that code is now
86
+ integrated in the Rakefile.
87
+ * Minor directory layout changes and cleanup (mostly for the extconf.rb file).
88
+ * Side note - it seems that the code for OS X *does* work, at least on 10.4.10.
89
+ I can only conclude that previous reports about it failing were related to
90
+ bugs in OS X or were really just build issues. Apologies (and thanks, again)
91
+ to David Felstead for the code. However, see the README for more information
92
+ specific to OS X, as there are shortcomings.
93
+
94
+ == 0.7.5 - 23-Nov-2006
95
+ * Fixed int/long issues for Linux. Thanks go to Matt Lightner for the spot.
96
+ * Minor documentation fixes and changes to the extconf.rb file.
97
+
98
+ == 0.7.4 - 20-Nov-2006
99
+ * Added a patch that deals with the large file compilation issue on Solaris.
100
+ You no longer need to build Ruby with --disable-largefile, or build a
101
+ 64 bit Ruby, in order for this package to work. Thanks go to Steven Jenkins
102
+ for the information that led to the patch.
103
+ * Added inline rdoc to the source code.
104
+ * Added a gemspec.
105
+ * Fixed some potential 64 bit issues (struct declarations).
106
+ * Added preliminary support for Darwin (OS X). The code was provided by
107
+ David Felstead, but does not appear to compile successfully. Help wanted.
108
+
109
+ == 0.7.3 - 27-Oct-2005
110
+ * Fix for 1.8.3 and later (rb_pid_t). This should have only affected
111
+ Solaris.
112
+
113
+ == 0.7.2 - 15-May-2005
114
+ * Bug fix for the FreeBSD version that reads from /proc.
115
+ * Eliminated the test bug on Linux (inexplicably caused by File.copy). The
116
+ test suite should now run without segfaulting.
117
+ * Include bsd.c in tarball (oops).
118
+ * Minor test updates for FreeBSD.
119
+ * The 'pct_cpu' member for the BSD/kvm version has been changed to 'pctcpu'
120
+ for consistency with other platforms.
121
+
122
+ == 0.7.1 - 8-May-2005
123
+ * Bug fixed for the cmdline info on Linux. Thanks go to Arash Abedinzadeh
124
+ for the spot.
125
+ * Added an example program.
126
+ * Minor setup fix for Win32 in tc_all.rb.
127
+
128
+ == 0.7.0 - 25-Apr-2005
129
+ * Scrapped the C implementation for Windows in favor of an OLE + WMI pure Ruby
130
+ approach. See documentation for details.
131
+ * Added an optional lkvm implementation for BSD users. This is automatically
132
+ used if the /proc filesystem isn't found.
133
+ * Added prusage info for the Solaris version.
134
+ * Added name, eid, euid, gid and guid information for Linux. Thanks go to
135
+ James Hranicky for the patch.
136
+ * Fixed some potential bugs in the Linux version. Thanks go to James
137
+ Hranicky for the spot.
138
+ * Added the 'sys/top' package.
139
+ * ProcTable.fields no longer supports a block form.
140
+ * The BTIME (boot time) information has been removed from the Linux version.
141
+ If you want that information, use sys-uptime instead.
142
+ * The .html and .rd files have been removed. You can generate html on your
143
+ own with rdoc if you like.
144
+ * Some code cleanup on the C side of the house.
145
+ * Most documents made rdoc friendly.
146
+ * Renamed 'install_pure_ruby.rb' to just 'install.rb'.
147
+ * Removed the 'INSTALL' file. Installation instructions are in the README.
148
+ * Some test suite cleanup and reorganization.
149
+ * Moved project to RubyForge.
150
+
151
+ == 0.6.4 - 31-Mar-2004
152
+ * Fixed a bug in the pure Ruby version for Win32. Thanks go to Mark Hudson
153
+ for the spot.
154
+ * Fixed a bug in the C implementation for Win32 where the cmdline and path
155
+ values were sometimes wrong for running processes. Thanks go to Park Heesob
156
+ for the fix.
157
+ * Updated the VERSION constant and removed the VERSION class method in the
158
+ pure Ruby version for Win32.
159
+ * Updated install_pure_ruby.rb and test.rb scripts.
160
+ * Updated warranty information.
161
+ * The extconf.rb script has been revamped. See the INSTALL and README files
162
+ for important changes since the last release.
163
+ * The start ProcInfo struct member on Solaris, HP-UX and FreeBSD is now a
164
+ Time object, not a Fixnum/Bignum.
165
+ * Modified linux.c yet again to make gcc happy when it comes to multi-line
166
+ string literals.
167
+ * Minor change to way process state is handled on HP-UX.
168
+ * Documentation additions and updates, including warranty information.
169
+
170
+ == 0.6.3 - 24-Feb-2004
171
+ * Fixed a bug in the Solaris version where the cmd_args array did not
172
+ necessarily contain data on 2.7 and later. The current patch still
173
+ does not quite fix the problem for 2.6 and earlier but can be easily
174
+ derived manually by parsing the cmdline string.
175
+
176
+ == 0.6.2 - 20-Jan-2004
177
+ * Fixed a small memory leak in the solaris version.
178
+
179
+ == 0.6.1 - 31-Dec-2003
180
+ * Fixed a minor bug in the cmdline field on Linux where a blank character
181
+ was being appended to the end of the field.
182
+ * Fixed a minor annoyance where the windows.rb file was being copied into
183
+ the Ruby lib directory on install.
184
+ * Added a test_memleak.rb file. Currently only supported on Linux and
185
+ only does a file descriptor count check. I plan to expand this to
186
+ other platforms in the future.
187
+ * Minor test suite changes
188
+ * MANIFEST correction and update.
189
+
190
+ == 0.6.0 - 22-Oct-2003
191
+ * Significant API change (and thus, a version jump) - only a
192
+ single argument is now accepted to the ps() method, and only a PID
193
+ (Fixnum) is regarded as a valid argument.
194
+ * Calling ps() with a pid returns a single ProcTable struct (or nil
195
+ if the pid is not found), instead of a one element array.
196
+ * Argument to ps() now works properly on HP-UX and Win32.
197
+ * Removed the '#include <sys/types32.h>' in sunos.h. It wasn't needed
198
+ and you're not supposed to include it directly.
199
+ * Fixed 2.6 compatibility issue with regards to cmdline on Solaris.
200
+ * Removed the ProcStatException completely on Linux. There was no reason
201
+ to fail on a directory read for /proc/xxx/stat. If the read fails
202
+ (meaning the process died in the middle of collecting info for it), it
203
+ is simply ignored.
204
+ * The ttynum bug on HPUX has been fixed. In addition, the return value for
205
+ this field is now a string rather than an int and the field name has
206
+ been changed to "ttydev".
207
+ * The ttynum field has been changed to ttydev on Solaris and HPUX. On
208
+ Solaris, the ttydev is now reported as -1 if there is no associated tty.
209
+ In a future release, Solaris and the other *nix platforms will be changed
210
+ so that ttydev is always a device name (i.e String).
211
+ * Added plain text documentation for all platforms.
212
+ * Some test suite cleanup.
213
+ * Changed .rd2 extension to just '.rd'.
214
+
215
+ == 0.5.2 - 18-Jul-2003
216
+ * Modified cmdline to extend past the traditional 80 character limit on
217
+ Solaris, where possible (Solaris 2.6+ only).
218
+ * Added the cmdline_args and num_args fields on Solaris, which returns
219
+ an array of cmdline arguments and the number of cmdline arguments,
220
+ respectively.
221
+ * Minor modification to fields() method, in addition to warning cleanup
222
+ for Solaris.
223
+ * Changed "defunct" state string to "zombie" for Solaris.
224
+ * Should cleanly compile with -Wall -W now (gcc) on Solaris.
225
+ * Added solaris.txt to doc directory.
226
+ * MANIFEST corrections.
227
+
228
+ == 0.5.1 - 16-Jul-2003
229
+ * Fixed a nasty file descriptor bug in the Linux code, where file descriptors
230
+ were continuously being used up.
231
+ * Added the BTIME (boot time) constant for Linux.
232
+ * Fixed up the test/test.rb file a bit.
233
+ * Added BTIME tests to tc_linux.rb.
234
+
235
+ == 0.5.0 - 11-Jul-200
236
+ * Added HP-UX support!
237
+ * Note that passing PID's or strings as arguments to ps() is not supported
238
+ in the HP-UX version. This functionality will be stripped out of the
239
+ other versions in a future release. See the README file for more details.
240
+ * Removed the VERSION() class method. Use the constant instead.
241
+ * Separated the rd docs from their respective source files. Now in the doc
242
+ directory.
243
+ * Got rid of the interactive html generation in extconf.rb.
244
+ * Changed License to Artistic.
245
+
246
+ == 0.4.3 - 30-May-2003
247
+ * Added a version.h file to store the version number. Modified all of the
248
+ C source files to use that instead of hard coding the version everywhere.
249
+ * Added a generic test.rb script for those without TestUnit installed, or
250
+ just futzing in general. Modified the extconf.rb script to copy this
251
+ instead of writing an inline HERE document.
252
+ * Modified extconf.rb so that it builds with mingw or cygwin. Thanks go to
253
+ Peter Fischer for the spot and patch.
254
+ * Modified test suite to work with TestUnit 0.1.6 or 0.1.8.
255
+
256
+ == 0.4.2 - 14-Apr-2003
257
+ * Added pure Ruby version for Win32 - thanks Park Heesob.
258
+ * Modified extconf.rb file to handle pure Ruby versions.
259
+ * Added install_pure_ruby.rb file, an alternate installation
260
+ script for pure Ruby versions.
261
+
262
+ == 0.4.1 - 31-Mar-2003
263
+ * Added support for Solaris 2.5.x.
264
+ * All exceptions are now a direct subclass of StandardError.
265
+ * Value returned for wchan now more meaningful (2.5.x only for now).
266
+ * Fixed the start, utime and ctime for FreeBSD.
267
+ * Minor fix to FreeBSD test suite.
268
+ * Some changes to extconf.rb.
269
+ * Minor doc changes.
270
+ * Added License and Copyright info.
271
+
272
+ == 0.4.0 - 10-Mar-2003
273
+ * Added MS Windows support (non-cygwin).
274
+ * Added environment information for Linux version.
275
+ * Added real exceptions (type depends on platform).
276
+ * Added a test suite (for those with testunit installed).
277
+ * Removed the sys-uname requirement.
278
+ * Heavily modified the extconf.rb script.
279
+ * Changed "Changelog" to "CHANGES" and "Manifest" to "MANIFEST".
280
+ * Added a VERSION constant and class method.
281
+ * Minor internal directory layout change (put 'os' under 'lib').
282
+ * Changed package name to lower case.
283
+ * Doc changes, including license information.
284
+
285
+ == 0.3.1 - 16-Aug-2002
286
+ * Added a "comm" field to the sunos version. I am going to try to make this a
287
+ common field for all platforms to help reduce RUBY_PLATFORM checking.
288
+ * Fixed the release date for 0.3.0 (was accidentally marked *July*).
289
+ * Added an INSTALL file.
290
+ * Minor documentation change to the sunos.c source file.
291
+
292
+ == 0.3.0 - 11-Aug-2002
293
+ * Added FreeBSD support!
294
+ * Struct name changed to just "ProcTableStruct" to be compliant with future
295
+ versions of Ruby.
296
+ * The ps() function now returns an array of ProcTableStruct's in lvalue context.
297
+ * Fixed the ability to search by process name in Linux.
298
+ * Modified Linux "comm" field to strip parenthesis.
299
+ * Some doc changes/additions.
300
+ * Added Sean Chittenden to the "Acknowledgements" section. Sean provided me
301
+ with access to a FreeBSD box, which is how I was able to provide FreeBSD
302
+ support. Thanks Sean!
303
+
304
+ == 0.2.0 - 19-Jul-2002
305
+ * Added the ability to search by process name.
306
+ * test.rb modified to be cross-platform.
307
+ * Solaris - fixed bug with fname (was accidentally called "name").
308
+
309
+ == 0.1.0 - 2-Jul-2002
310
+ - Initial release.
data/MANIFEST ADDED
@@ -0,0 +1,30 @@
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 ADDED
@@ -0,0 +1,112 @@
1
+ == Description
2
+ A Ruby interface for gathering process information.
3
+
4
+ == Prerequisites
5
+ * Test::Unit 2.x (development only)
6
+
7
+ == Supported Platforms
8
+ * Windows 2000 or later
9
+ * Linux 2.6+
10
+ * BSD (various flavors)
11
+ * Solaris 8+
12
+ * HP-UX 10+
13
+ * OS X 10.4+
14
+
15
+ == Installation
16
+ gem install sys-proctable
17
+
18
+ You may need to specify a platform in some cases. For example:
19
+
20
+ gem install sys-proctable --platform mswin32 # Windows
21
+ gem install sys-proctable --platform sunos # Solaris
22
+ gem install sys-proctable --platform linux # Linux
23
+ gem install sys-proctable --platform freebsd # BSD (any flavor)
24
+
25
+ == Synopsis
26
+ require 'sys/proctable'
27
+ include Sys
28
+
29
+ # Everything
30
+ ProcTable.ps{ |p|
31
+ puts p.pid.to_s
32
+ puts p.comm
33
+ # ...
34
+ }
35
+
36
+ # Just one process
37
+ s = ProcTable.ps(2123)
38
+ puts s.pid.to_s
39
+ puts s.comm
40
+ # ...
41
+
42
+ # Return the results as an array of ProcTableStructs
43
+ a = ProcTable.ps
44
+ a.each do |p|
45
+ puts a.pid
46
+ # ...
47
+ end
48
+
49
+ == Notes
50
+ Windows users may pass a host name as a second argument to get process
51
+ information from a different host. This relies on the WMI service running.
52
+
53
+ == Known Issues
54
+ === BSD
55
+ A kvm interface is used. That means the owner of the process using the
56
+ sys-proctable library needs to be a member of the kvm group (or root).
57
+
58
+ === Solaris
59
+ The cmdline member on Solaris is limited to 80 characters unless you (or
60
+ your program) own the process. This is a Solaris design flaw/feature.
61
+
62
+ === Thread Safety
63
+ I am not currently using a thread-safe version of readdir() for versions
64
+ of this library that use C. I am not especially concerned about it either.
65
+ If you are trying to read information out of /proc from different threads
66
+ at the same time there is something seriously wrong with your code logic.
67
+ Using readdir_r() still won't solve all potential thread safety issues anyway.
68
+
69
+ == Future Plans
70
+ Research has indicated that the kvm approach is less favored than a sysctl
71
+ approach on BSD variants. I will try to add this interface in a future
72
+ release.
73
+
74
+ == Acknowledgements
75
+ This library is largely based on the Perl module Proc::ProcessTable by
76
+ Dan Urist. Many ideas, as well as large chunks of code, were taken
77
+ from his work. So, a big THANK YOU goes out to Dan Urist.
78
+
79
+ A big thanks also goes out to Mike Hall who was very helpful with ideas,
80
+ logic and testing.
81
+
82
+ Thanks also go to Sean Chittenden for providing an account on one of his
83
+ FreeBSD machines. This is how the FreeBSD support was (initially) added.
84
+
85
+ Thanks go to James Hranicky for providing a patch that grabs name, eid,
86
+ euid, gid and guid info in the Linux version, along with some general
87
+ debugging help.
88
+
89
+ Thanks go to David Felstead for the original OS X code. Thanks also go
90
+ to Matthias Zirnstein for adding cmdline support for OS X.
91
+
92
+ Finally I'd like to thank all the folks who have submitted bug reports
93
+ and/or patches.
94
+
95
+ == Help Wanted
96
+ I do not have access to all platforms. If your platform is not supported
97
+ then you will need to either submit a patch or give me a remote account
98
+ on a box with a compiler so that I can write the code.
99
+
100
+ == More documentation
101
+ See the documentation under the 'doc' directory for more information,
102
+ including platform specific notes and issues.
103
+
104
+ == License
105
+ Artistic 2.0
106
+
107
+ == Copyright
108
+ (C) 2003-2012 Daniel J. Berger
109
+ All Rights Reserved.
110
+
111
+ == Author
112
+ Daniel J. Berger
data/Rakefile ADDED
@@ -0,0 +1,179 @@
1
+ require 'rake'
2
+ require 'rake/clean'
3
+ require 'rake/testtask'
4
+ require 'rbconfig'
5
+ include RbConfig
6
+
7
+ CLEAN.include(
8
+ '**/*.core', # Core dump files
9
+ '**/*.gem', # Gem files
10
+ '**/*.rbc', # Rubinius
11
+ '.rbx', '**/*/.rbx', # Rubinius
12
+ '**/*.o', # C object file
13
+ '**/*.log', # Ruby extension build log
14
+ '**/Makefile', # C Makefile
15
+ '**/conftest.dSYM', # OS X build directory
16
+ "**/*.#{CONFIG['DLEXT']}" # C shared object
17
+ )
18
+
19
+ desc 'Build the sys-proctable library for C versions of sys-proctable'
20
+ task :build => [:clean] do
21
+ case CONFIG['host_os']
22
+ when /bsd/i
23
+ dir = 'ext/bsd'
24
+ when /darwin/i
25
+ dir = 'ext/darwin'
26
+ when /hpux/i
27
+ dir = 'ext/hpux'
28
+ end
29
+
30
+ unless CONFIG['host_os'] =~ /win32|mswin|dos|cygwin|mingw|windows|linux|sunos|solaris/i || RUBY_ENGINE == "jruby"
31
+ Dir.chdir(dir) do
32
+ ruby 'extconf.rb'
33
+ sh 'make'
34
+ cp 'proctable.' + CONFIG['DLEXT'], 'sys'
35
+ end
36
+ end
37
+ end
38
+
39
+ desc 'Install the sys-proctable library'
40
+ task :install => [:build] do
41
+ file = nil
42
+ dir = File.join(CONFIG['sitelibdir'], 'sys')
43
+
44
+ Dir.mkdir(dir) unless File.exists?(dir)
45
+
46
+ case CONFIG['host_os']
47
+ when /mswin|win32|msdos|cygwin|mingw|windows/i
48
+ file = 'lib/windows/sys/proctable.rb'
49
+ when /linux|java/i
50
+ file = 'lib/linux/sys/proctable.rb'
51
+ when /sunos|solaris/i
52
+ file = 'lib/sunos/sys/proctable.rb'
53
+ when /bsd/i
54
+ Dir.chdir('ext/bsd'){ sh 'make install' }
55
+ when /darwin/i
56
+ Dir.chdir('ext/darwin'){ sh 'make install' }
57
+ when /hpux/i
58
+ Dir.chdir('ext/hpux'){ sh 'make install' }
59
+ end
60
+
61
+ cp(file, dir, :verbose => true) if file
62
+ end
63
+
64
+ desc 'Uninstall the sys-proctable library'
65
+ task :uninstall do
66
+ case CONFIG['host_os']
67
+ when /win32|mswin|dos|cygwin|mingw|windows|linux|sunos|solaris/i
68
+ dir = File.join(CONFIG['sitelibdir'], 'sys')
69
+ file = File.join(dir, 'proctable.rb')
70
+ else
71
+ dir = File.join(CONFIG['sitearchdir'], 'sys')
72
+ file = File.join(dir, 'proctable.' + CONFIG['DLEXT'])
73
+ end
74
+
75
+ rm(file)
76
+ end
77
+
78
+ desc 'Run the benchmark suite'
79
+ task :bench => [:build] do
80
+ sh "ruby -Ilib benchmarks/bench_ps.rb"
81
+ end
82
+
83
+ desc 'Run the example program'
84
+ task :example => [:build] do
85
+ sh 'ruby -Ilib -Iext examples/example_ps.rb'
86
+ end
87
+
88
+ desc 'Run the test suite'
89
+ Rake::TestTask.new do |t|
90
+ task :test => :build
91
+ t.libs << 'test' << '.'
92
+
93
+ case CONFIG['host_os']
94
+ when /mswin|msdos|cygwin|mingw|windows/i
95
+ t.test_files = FileList['test/test_sys_proctable_windows.rb']
96
+ t.libs << 'lib/windows'
97
+ when /linux/i
98
+ t.test_files = FileList['test/test_sys_proctable_linux.rb']
99
+ t.libs << 'lib/linux'
100
+ when /sunos|solaris/i
101
+ t.test_files = FileList['test/test_sys_proctable_sunos.rb']
102
+ t.libs << 'lib/sunos'
103
+ when /darwin/i
104
+ t.libs << 'ext/darwin'
105
+ t.test_files = FileList['test/test_sys_proctable_darwin.rb']
106
+ when /bsd/i
107
+ t.libs << 'ext/bsd'
108
+ t.test_files = FileList['test/test_sys_proctable_bsd.rb']
109
+ when /hpux/i
110
+ t.libs << 'ext/hpux'
111
+ t.test_files = FileList['test/test_sys_proctable_hpux.rb']
112
+ end
113
+ end
114
+
115
+ namespace :gem do
116
+ desc 'Create a gem'
117
+ task :create => [:clean] do
118
+ spec = eval(IO.read('sys-proctable.gemspec'))
119
+
120
+ # I've had to manually futz with the spec here in some cases
121
+ # in order to get the universal platform settings I want because
122
+ # of some bugginess in Rubygems' platform.rb.
123
+ #
124
+ case CONFIG['host_os']
125
+ when /bsd/i
126
+ spec.platform = Gem::Platform.new(['universal', 'freebsd'])
127
+ spec.platform.version = nil
128
+ spec.files << 'ext/bsd/sys/proctable.c'
129
+ spec.extra_rdoc_files << 'ext/bsd/sys/proctable.c'
130
+ spec.test_files << 'test/test_sys_proctable_bsd.rb'
131
+ spec.extensions = ['ext/bsd/extconf.rb']
132
+ when /darwin/i
133
+ spec.platform = Gem::Platform.new(['universal', 'darwin'])
134
+ spec.files << 'ext/darwin/sys/proctable.c'
135
+ spec.extra_rdoc_files << 'ext/darwin/sys/proctable.c'
136
+ spec.test_files << 'test/test_sys_proctable_darwin.rb'
137
+ spec.extensions = ['ext/darwin/extconf.rb']
138
+ when /hpux/i
139
+ spec.platform = Gem::Platform.new(['universal', 'hpux'])
140
+ spec.files << 'ext/hpux/sys/proctable.c'
141
+ spec.extra_rdoc_files << 'ext/hpux/sys/proctable.c'
142
+ spec.test_files << 'test/test_sys_proctable_hpux.rb'
143
+ spec.extensions = ['ext/hpux/extconf.rb']
144
+ when /linux/i
145
+ spec.platform = Gem::Platform.new(['universal', 'linux'])
146
+ spec.require_paths = ['lib', 'lib/linux']
147
+ spec.files += ['lib/linux/sys/proctable.rb']
148
+ spec.test_files << 'test/test_sys_proctable_linux.rb'
149
+ when /java/i
150
+ spec.platform = Gem::Platform.new(['universal', 'java'])
151
+ spec.require_paths = ['lib', 'lib/linux']
152
+ spec.files += ['lib/linux/sys/proctable.rb']
153
+ spec.test_files << 'test/test_sys_proctable_linux.rb'
154
+ when /sunos|solaris/i
155
+ spec.platform = Gem::Platform.new(['universal', 'solaris'])
156
+ spec.require_paths = ['lib', 'lib/sunos']
157
+ spec.files += ['lib/sunos/sys/proctable.rb']
158
+ spec.test_files << 'test/test_sys_proctable_sunos.rb'
159
+ when /mswin|win32|dos|cygwin|mingw|windows/i
160
+ spec.platform = Gem::Platform.new(['universal', 'mingw32'])
161
+ spec.require_paths = ['lib', 'lib/windows']
162
+ spec.files += ['lib/windows/sys/proctable.rb']
163
+ spec.test_files << 'test/test_sys_proctable_windows.rb'
164
+ end
165
+
166
+ # https://github.com/rubygems/rubygems/issues/147
167
+ spec.original_platform = spec.platform
168
+
169
+ Gem::Builder.new(spec).build
170
+ end
171
+
172
+ desc 'Install the sys-proctable library as a gem'
173
+ task :install => [:create] do
174
+ gem_name = Dir['*.gem'].first
175
+ sh "gem install #{gem_name}"
176
+ end
177
+ end
178
+
179
+ task :default => :test
@@ -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 ADDED
@@ -0,0 +1,47 @@
1
+ = Description
2
+ A simple 'top' interface for Ruby
3
+
4
+ = Prerequisites
5
+ Requires the "sys/proctable" package (which should be installed along
6
+ with this package).
7
+
8
+ = Synopsis
9
+ require "sys/top"
10
+
11
+ Sys::Top.top(5).each{ |ps|
12
+ p ps
13
+ }
14
+
15
+ = Constants
16
+ VERSION
17
+ Returns the version number of this package as a String.
18
+
19
+ = Class Methods
20
+ Sys::Top.top(number=10, field="pctcpu")
21
+ Returns an array of ProcTableStruct's. The size of the array (i.e. the
22
+ number of processes) that it returns is based on +number+, and sorted by
23
+ +pctcpu+. By default, the size and field values are 10 and "pctcpu",
24
+ respectively.
25
+
26
+ = Notes
27
+ Not all fields are available on all platforms. Please check your
28
+ platform specific documentation for which fields are available.
29
+
30
+ = Bugs
31
+ None that I'm aware of. Please log bug reports on the project page at
32
+ http://www.rubyforge.org/projects/sysutils
33
+
34
+ = License
35
+ Artistic 2.0
36
+
37
+ = Copyright
38
+ (C) 2004-2009 Daniel J. Berger
39
+ All Rights Reserved.
40
+
41
+ = Warranty
42
+ This package is provided "as is" and without any express or
43
+ implied warranties, including, without limitation, the implied
44
+ warranties of merchantability and fitness for a particular purpose.
45
+
46
+ = Author
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
+ }
@@ -0,0 +1,281 @@
1
+ # The Sys module serves as a namespace only.
2
+ module Sys
3
+
4
+ # The ProcTable class encapsulates process table information.
5
+ class ProcTable
6
+
7
+ # Error typically raised if the ProcTable.ps method fails.
8
+ class Error < StandardError; end
9
+
10
+ # There is no constructor
11
+ private_class_method :new
12
+
13
+ # The version of the sys-proctable library
14
+ VERSION = '0.9.2'
15
+
16
+ private
17
+
18
+ @mem_total = IO.read("/proc/meminfo")[/MemTotal.*/].split[1].to_i * 1024 rescue nil
19
+ @boot_time = IO.read("/proc/stat")[/btime.*/].split.last.to_i rescue nil
20
+
21
+ @fields = [
22
+ 'cmdline', # Complete command line
23
+ 'cwd', # Current working directory
24
+ 'environ', # Environment
25
+ 'exe', # Actual pathname of the executed command
26
+ 'fd', # File descriptors open by process
27
+ 'root', # Root directory of process
28
+ 'pid', # Process ID
29
+ 'comm', # Filename of executable
30
+ 'state', # Single character state abbreviation
31
+ 'ppid', # Parent process ID
32
+ 'pgrp', # Process group
33
+ 'session', # Session ID
34
+ 'tty_nr', # TTY (terminal) associated with the process
35
+ 'tpgid', # Group ID of the TTY
36
+ 'flags', # Kernel flags
37
+ 'minflt', # Number of minor faults
38
+ 'cminflt', # Number of minor faults of waited-for children
39
+ 'majflt', # Number of major faults
40
+ 'cmajflt', # Number of major faults of waited-for children
41
+ 'utime', # Number of user mode jiffies
42
+ 'stime', # Number of kernel mode jiffies
43
+ 'cutime', # Number of children's user mode jiffies
44
+ 'cstime', # Number of children's kernel mode jiffies
45
+ 'priority', # Nice value plus 15
46
+ 'nice', # Nice value
47
+ 'itrealvalue', # Time in jiffies before next SIGALRM
48
+ 'starttime', # Time in jiffies since system boot
49
+ 'vsize', # Virtual memory size in bytes
50
+ 'rss', # Resident set size
51
+ 'rlim', # Current limit on the rss in bytes
52
+ 'startcode', # Address above which program text can run
53
+ 'endcode', # Address below which program text can run
54
+ 'startstack', # Address of the startstack
55
+ 'kstkesp', # Kernel stack page address
56
+ 'kstkeip', # Kernel instruction pointer
57
+ 'signal', # Bitmap of pending signals
58
+ 'blocked', # Bitmap of blocked signals
59
+ 'sigignore', # Bitmap of ignored signals
60
+ 'sigcatch', # Bitmap of caught signals
61
+ 'wchan', # Channel in which the process is waiting
62
+ 'nswap', # Number of pages swapped
63
+ 'cnswap', # Cumulative nswap for child processes
64
+ 'exit_signal', # Signal to be sent to parent when process dies
65
+ 'processor', # CPU number last executed on
66
+ 'rt_priority', # Real time scheduling priority
67
+ 'policy', # Scheduling policy
68
+ 'name', # Process name
69
+ 'uid', # Real user ID
70
+ 'euid', # Effective user ID
71
+ 'gid', # Real group ID
72
+ 'egid', # Effective group ID
73
+ 'pctcpu', # Percent of CPU usage (custom field)
74
+ 'pctmem' # Percent of Memory usage (custom field)
75
+ ]
76
+
77
+ public
78
+
79
+ ProcTableStruct = Struct.new('ProcTableStruct', *@fields)
80
+
81
+ # In block form, yields a ProcTableStruct for each process entry that you
82
+ # have rights to. This method returns an array of ProcTableStruct's in
83
+ # non-block form.
84
+ #
85
+ # If a +pid+ is provided, then only a single ProcTableStruct is yielded or
86
+ # returned, or nil if no process information is found for that +pid+.
87
+ #
88
+ # Example:
89
+ #
90
+ # # Iterate over all processes
91
+ # ProcTable.ps do |proc_info|
92
+ # p proc_info
93
+ # end
94
+ #
95
+ # # Print process table information for only pid 1001
96
+ # p ProcTable.ps(1001)
97
+ #
98
+ #--
99
+ # It's possible that a process could terminate while gathering
100
+ # information for that process. When that happens, this library
101
+ # will simply skip to the next record. In short, this library will
102
+ # either return all information for a process, or none at all.
103
+ #
104
+ def self.ps(pid=nil)
105
+ array = block_given? ? nil : []
106
+ struct = nil
107
+
108
+ raise TypeError unless pid.is_a?(Fixnum) if pid
109
+
110
+ Dir.foreach("/proc"){ |file|
111
+ next if file =~ /\D/ # Skip non-numeric directories
112
+ next unless file.to_i == pid if pid
113
+
114
+ struct = ProcTableStruct.new
115
+
116
+ # Get /proc/<pid>/cmdline information. Strip out embedded nulls.
117
+ begin
118
+ data = IO.read("/proc/#{file}/cmdline").tr("\000", ' ').strip
119
+ struct.cmdline = data
120
+ rescue
121
+ next # Process terminated, on to the next process
122
+ end
123
+
124
+ # Get /proc/<pid>/cwd information
125
+ struct.cwd = File.readlink("/proc/#{file}/cwd") rescue nil
126
+
127
+ # Get /proc/<pid>/environ information. Environment information
128
+ # is represented as a Hash, with the environment variable as the
129
+ # key and its value as the hash value.
130
+ struct.environ = {}
131
+
132
+ begin
133
+ IO.read("/proc/#{file}/environ").split("\0").each{ |str|
134
+ key, value = str.split('=')
135
+ struct.environ[key] = value
136
+ }
137
+ rescue Errno::EACCES, Errno::ESRCH, Errno::ENOENT
138
+ # Ignore and move on.
139
+ end
140
+
141
+ # Get /proc/<pid>/exe information
142
+ struct.exe = File.readlink("/proc/#{file}/exe") rescue nil
143
+
144
+ # Get /proc/<pid>/fd information. File descriptor information
145
+ # is represented as a Hash, with the fd as the key, and its
146
+ # symlink as the value.
147
+ struct.fd = {}
148
+
149
+ begin
150
+ Dir["/proc/#{file}/fd/*"].each do |fd|
151
+ struct.fd[File.basename(fd)] = File.readlink(fd) rescue nil
152
+ end
153
+ rescue
154
+ # Ignore and move on
155
+ end
156
+
157
+ # Get /proc/<pid>/root information
158
+ struct.root = File.readlink("/proc/#{file}/root") rescue nil
159
+
160
+ # Get /proc/<pid>/stat information
161
+ stat = IO.read("/proc/#{file}/stat") rescue next
162
+
163
+ # Deal with spaces in comm name. Courtesy of Ara Howard.
164
+ re = %r/\([^\)]+\)/
165
+ comm = stat[re]
166
+ comm.tr!(' ', '-')
167
+ stat[re] = comm
168
+
169
+ stat = stat.split
170
+
171
+ struct.pid = stat[0].to_i
172
+ struct.comm = stat[1].tr('()','') # Remove parens
173
+ struct.state = stat[2]
174
+ struct.ppid = stat[3].to_i
175
+ struct.pgrp = stat[4].to_i
176
+ struct.session = stat[5].to_i
177
+ struct.tty_nr = stat[6].to_i
178
+ struct.tpgid = stat[7].to_i
179
+ struct.flags = stat[8].to_i
180
+ struct.minflt = stat[9].to_i
181
+ struct.cminflt = stat[10].to_i
182
+ struct.majflt = stat[11].to_i
183
+ struct.cmajflt = stat[12].to_i
184
+ struct.utime = stat[13].to_i
185
+ struct.stime = stat[14].to_i
186
+ struct.cutime = stat[15].to_i
187
+ struct.cstime = stat[16].to_i
188
+ struct.priority = stat[17].to_i
189
+ struct.nice = stat[18].to_i
190
+ # Skip 19
191
+ struct.itrealvalue = stat[20].to_i
192
+ struct.starttime = stat[21].to_i
193
+ struct.vsize = stat[22].to_i
194
+ struct.rss = stat[23].to_i
195
+ struct.rlim = stat[24].to_i
196
+ struct.startcode = stat[25].to_i
197
+ struct.endcode = stat[26].to_i
198
+ struct.startstack = stat[27].to_i
199
+ struct.kstkesp = stat[28].to_i
200
+ struct.kstkeip = stat[29].to_i
201
+ struct.signal = stat[30].to_i
202
+ struct.blocked = stat[31].to_i
203
+ struct.sigignore = stat[32].to_i
204
+ struct.sigcatch = stat[33].to_i
205
+ struct.wchan = stat[34].to_i
206
+ struct.nswap = stat[35].to_i
207
+ struct.cnswap = stat[36].to_i
208
+ struct.exit_signal = stat[37].to_i
209
+ struct.processor = stat[38].to_i
210
+ struct.rt_priority = stat[39].to_i
211
+ struct.policy = stat[40].to_i
212
+
213
+ # Get /proc/<pid>/status information (name, uid, euid, gid, egid)
214
+ IO.foreach("/proc/#{file}/status") do |line|
215
+ case line
216
+ when /Name:\s*?(\w+)/
217
+ struct.name = $1
218
+ when /Uid:\s*?(\d+)\s*?(\d+)/
219
+ struct.uid = $1.to_i
220
+ struct.euid = $2.to_i
221
+ when /Gid:\s*?(\d+)\s*?(\d+)/
222
+ struct.gid = $1.to_i
223
+ struct.egid = $2.to_i
224
+ end
225
+ end
226
+
227
+ # If cmdline is empty use comm instead
228
+ struct.cmdline = struct.comm if struct.cmdline.empty?
229
+
230
+ # Manually calculate CPU and memory usage
231
+ struct.pctcpu = get_pctcpu(struct.utime, struct.starttime)
232
+ struct.pctmem = get_pctmem(struct.rss)
233
+
234
+ struct.freeze # This is read-only data
235
+
236
+ if block_given?
237
+ yield struct
238
+ else
239
+ array << struct
240
+ end
241
+ }
242
+
243
+ pid ? struct : array
244
+ end
245
+
246
+ # Returns an array of fields that each ProcTableStruct will contain. This
247
+ # may be useful if you want to know in advance what fields are available
248
+ # without having to perform at least one read of the /proc table.
249
+ #
250
+ # Example:
251
+ #
252
+ # Sys::ProcTable.fields.each{ |field|
253
+ # puts "Field: #{field}"
254
+ # }
255
+ #
256
+ def self.fields
257
+ @fields
258
+ end
259
+
260
+ private
261
+
262
+ # Calculate the percentage of memory usage for the given process.
263
+ #
264
+ def self.get_pctmem(rss)
265
+ return nil unless @mem_total
266
+ page_size = 4096
267
+ rss_total = rss * page_size
268
+ sprintf("%3.2f", (rss_total.to_f / @mem_total) * 100).to_f
269
+ end
270
+
271
+ # Calculate the percentage of CPU usage for the given process.
272
+ #
273
+ def self.get_pctcpu(utime, start_time)
274
+ return nil unless @boot_time
275
+ hertz = 100.0
276
+ utime = (utime * 10000).to_f
277
+ stime = (start_time.to_f / hertz) + @boot_time
278
+ sprintf("%3.2f", (utime / 10000.0) / (Time.now.to_i - stime)).to_f
279
+ end
280
+ end
281
+ end
data/lib/sys/top.rb ADDED
@@ -0,0 +1,29 @@
1
+ require 'sys/proctable'
2
+
3
+ # The Sys module serves as a namespace only
4
+ module Sys
5
+
6
+ # The Top class serves as a toplevel name for the 'top' method.
7
+ class Top
8
+
9
+ # The version of the sys-top library
10
+ VERSION = '1.0.3'
11
+
12
+ # Returns an array of Struct::ProcTableStruct elements containing up
13
+ # to +num+ elements, sorted by +field+. The default number of elements
14
+ # is 10, while the default field is 'pctcpu'.
15
+ #
16
+ # Exception: the default sort field is 'pid' on Linux and Windows.
17
+ #
18
+ def self.top(num=10, field='pctcpu')
19
+ field = field.to_s if field.is_a?(Symbol)
20
+
21
+ # Sort by pid on Windows by default
22
+ if File::ALT_SEPARATOR && field == 'pctcpu'
23
+ field = 'pid'
24
+ end
25
+
26
+ Sys::ProcTable.ps.sort_by{ |obj| obj.send(field) || '' }[0..num-1]
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,41 @@
1
+ require 'rubygems'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'rumblinthebronx-sys-proctable'
5
+ spec.version = '0.9.5'
6
+ spec.author = 'Daniel J. Berger'
7
+ spec.license = 'Artistic 2.0'
8
+ spec.email = 'djberg96@gmail.com'
9
+ spec.homepage = 'http://www.rubyforge.org/projects/sysutils'
10
+ spec.platform = 'universal-java'
11
+ spec.summary = 'An interface for providing process table information'
12
+ spec.test_files = ['test/test_sys_proctable_all.rb']
13
+
14
+ # Additional files for your platform are added by the 'rake gem' task.
15
+ spec.files = [
16
+ 'benchmarks/bench_ps.rb',
17
+ 'examples/example_ps.rb',
18
+ 'lib/sys/top.rb',
19
+ 'lib/linux/sys/proctable.rb',
20
+ 'CHANGES',
21
+ 'MANIFEST',
22
+ 'Rakefile',
23
+ 'README',
24
+ 'sys-proctable.gemspec'
25
+ ]
26
+
27
+ spec.require_paths = ["lib", "lib/linux"]
28
+
29
+ spec.rubyforge_project = 'sysutils'
30
+ spec.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST', 'doc/top.txt']
31
+
32
+ spec.add_development_dependency('test-unit', '>= 2.4.0')
33
+
34
+ spec.description = <<-EOF
35
+ The sys-proctable library provides an interface for gathering information
36
+ about processes on your system, i.e. the process table. Most major
37
+ platforms are supported and, while different platforms may return
38
+ different information, the external interface is identical across
39
+ platforms.
40
+ EOF
41
+ end
@@ -0,0 +1,84 @@
1
+ #######################################################################
2
+ # test_sys_proctable_all.rb
3
+ #
4
+ # Test suite for methods common to all platforms. Generally speaking
5
+ # you should run this test case using the 'rake test' task.
6
+ #######################################################################
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+
10
+ require 'test/unit'
11
+ require 'sys/proctable'
12
+ require 'test/test_sys_top'
13
+ include Sys
14
+
15
+ class TC_ProcTable_All < Test::Unit::TestCase
16
+ def self.startup
17
+ @@windows = File::ALT_SEPARATOR
18
+ end
19
+
20
+ def setup
21
+ @pid = @@windows ? 0 : 1
22
+ end
23
+
24
+ def test_version
25
+ assert_equal('0.9.2', ProcTable::VERSION)
26
+ end
27
+
28
+ def test_fields
29
+ assert_respond_to(ProcTable, :fields)
30
+ assert_nothing_raised{ ProcTable.fields }
31
+ assert_kind_of(Array, ProcTable.fields)
32
+ assert_kind_of(String, ProcTable.fields.first)
33
+ end
34
+
35
+ def test_ps
36
+ assert_respond_to(ProcTable, :ps)
37
+ assert_nothing_raised{ ProcTable.ps }
38
+ assert_nothing_raised{ ProcTable.ps{} }
39
+ end
40
+
41
+ def test_ps_with_pid
42
+ assert_nothing_raised{ ProcTable.ps(0) }
43
+ end
44
+
45
+ def test_ps_with_explicit_nil
46
+ assert_nothing_raised{ ProcTable.ps(nil) }
47
+ assert_kind_of(Array, ProcTable.ps(nil))
48
+ end
49
+
50
+ def test_ps_return_value
51
+ assert_kind_of(Array, ProcTable.ps)
52
+ assert_kind_of(Struct::ProcTableStruct, ProcTable.ps(@pid))
53
+ assert_equal(nil, ProcTable.ps(999999999))
54
+ assert_equal(nil, ProcTable.ps(999999999){})
55
+ assert_equal(nil, ProcTable.ps{})
56
+ end
57
+
58
+ def test_ps_returned_struct_is_frozen
59
+ assert_true(ProcTable.ps.first.frozen?)
60
+ end
61
+
62
+ def test_ps_expected_errors
63
+ assert_raises(TypeError){ ProcTable.ps('vim') }
64
+ omit_if(@@windows, 'ArgumentError check skipped on MS Windows')
65
+ assert_raises(ArgumentError){ ProcTable.ps(0, 'localhost') }
66
+ end
67
+
68
+ def test_new_not_allowed
69
+ assert_raise(NoMethodError){ Sys::ProcTable.new }
70
+ end
71
+
72
+ def test_error_class_defined
73
+ assert_not_nil(Sys::ProcTable::Error)
74
+ assert_kind_of(StandardError, Sys::ProcTable::Error.new)
75
+ end
76
+
77
+ def teardown
78
+ @pid = nil
79
+ end
80
+
81
+ def self.teardown
82
+ @@windows = nil
83
+ end
84
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rumblinthebronx-sys-proctable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.5
5
+ prerelease:
6
+ platform: universal-java
7
+ authors:
8
+ - Daniel J. Berger
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: test-unit
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.4.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.4.0
30
+ description: ! " The sys-proctable library provides an interface for gathering
31
+ information\n about processes on your system, i.e. the process table. Most major\n
32
+ \ platforms are supported and, while different platforms may return\n different
33
+ information, the external interface is identical across\n platforms.\n"
34
+ email: djberg96@gmail.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files:
38
+ - CHANGES
39
+ - README
40
+ - MANIFEST
41
+ - doc/top.txt
42
+ files:
43
+ - benchmarks/bench_ps.rb
44
+ - examples/example_ps.rb
45
+ - lib/sys/top.rb
46
+ - lib/linux/sys/proctable.rb
47
+ - CHANGES
48
+ - MANIFEST
49
+ - Rakefile
50
+ - README
51
+ - sys-proctable.gemspec
52
+ - doc/top.txt
53
+ - test/test_sys_proctable_all.rb
54
+ homepage: http://www.rubyforge.org/projects/sysutils
55
+ licenses:
56
+ - Artistic 2.0
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ - lib/linux
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project: sysutils
76
+ rubygems_version: 1.8.24
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: An interface for providing process table information
80
+ test_files:
81
+ - test/test_sys_proctable_all.rb
82
+ has_rdoc: