sys-proctable 0.8.0-x86-freebsd-7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES ADDED
@@ -0,0 +1,260 @@
1
+ == 0.8.0 - 26-Jan-2009
2
+ * The Linux and Solaris versions of this library are now pure Ruby. Be warned,
3
+ however, that only Solaris 8 and later are now supported. This may change
4
+ in a future release if there's demand to support 2.6 and 2.7.
5
+ * Some Struct::ProcTableStruct members have changed. As a general rule they
6
+ now more closely match the C struct member name. See individual platforms
7
+ for more details.
8
+ * Bug fix for the cmd_args struct member on Solaris.
9
+ * Bug fixes for OS X. Added a VERSION constant, fixed struct name, and changed
10
+ pct_cpu to pctcpu.
11
+ * The .new method is now explicitly illegal.
12
+ * The Struct::ProcTableStruct instances are now frozen. This is read-only data.
13
+ * Added the peak_page_file_usage and status members on MS Windows. The status
14
+ member is always nil, but was added for completeness.
15
+ * Fixed the quota_peak_paged_pool_usage member on MS Windows.
16
+ * ProcTableError is now ProcTable::Error.
17
+ * Minor test case fix for kvm/bsd based versions.
18
+ * Added the 'time' library as a require for Windows (to parse MS date/time
19
+ format strings).
20
+ * The kvm (bsd.c) implementation now works for FreeBSD 7.
21
+ * Added many more tests.
22
+ * Added some benchmarking code in the 'benchmarks' directory.
23
+ * Added a 'bench' Rake task.
24
+ * Renamed the test_ps.rb file to example_ps.rb in order to avoid any possible
25
+ confusion with actual test files.
26
+ * Added an 'example' rake task to run the example file.
27
+
28
+ == 0.7.6 - 11-Jul-2007
29
+ * Fixed the starttime for Linux. Thanks go to Yaroslav Dmitriev for the spot.
30
+ * Fixed a bug in the MS Windows version within a private method that parsed
31
+ an MS specific date format. This was caused by a backwards incompatible
32
+ change in the Time.parse method in Ruby 1.8.6. See ruby-core: 11245 ff.
33
+ * Fixed the gemspec (I hope). Please let me know if you have problems.
34
+ * Added a Rakefile. Building, testing and installing should now be handled via
35
+ Rake tasks. The install.rb file has been removed - that code is now
36
+ integrated in the Rakefile.
37
+ * Minor directory layout changes and cleanup (mostly for the extconf.rb file).
38
+ * Side note - it seems that the code for OS X *does* work, at least on 10.4.10.
39
+ I can only conclude that previous reports about it failing were related to
40
+ bugs in OS X or were really just build issues. Apologies (and thanks, again)
41
+ to David Felstead for the code. However, see the README for more information
42
+ specific to OS X, as there are shortcomings.
43
+
44
+ == 0.7.5 - 23-Nov-2006
45
+ * Fixed int/long issues for Linux. Thanks go to Matt Lightner for the spot.
46
+ * Minor documentation fixes and changes to the extconf.rb file.
47
+
48
+ == 0.7.4 - 20-Nov-2006
49
+ * Added a patch that deals with the large file compilation issue on Solaris.
50
+ You no longer need to build Ruby with --disable-largefile, or build a
51
+ 64 bit Ruby, in order for this package to work. Thanks go to Steven Jenkins
52
+ for the information that led to the patch.
53
+ * Added inline rdoc to the source code.
54
+ * Added a gemspec.
55
+ * Fixed some potential 64 bit issues (struct declarations).
56
+ * Added preliminary support for Darwin (OS X). The code was provided by
57
+ David Felstead, but does not appear to compile successfully. Help wanted.
58
+
59
+ == 0.7.3 - 27-Oct-2005
60
+ * Fix for 1.8.3 and later (rb_pid_t). This should have only affected
61
+ Solaris.
62
+
63
+ == 0.7.2 - 15-May-2005
64
+ * Bug fix for the FreeBSD version that reads from /proc.
65
+ * Eliminated the test bug on Linux (inexplicably caused by File.copy). The
66
+ test suite should now run without segfaulting.
67
+ * Include bsd.c in tarball (oops).
68
+ * Minor test updates for FreeBSD.
69
+ * The 'pct_cpu' member for the BSD/kvm version has been changed to 'pctcpu'
70
+ for consistency with other platforms.
71
+
72
+ == 0.7.1 - 8-May-2005
73
+ * Bug fixed for the cmdline info on Linux. Thanks go to Arash Abedinzadeh
74
+ for the spot.
75
+ * Added an example program.
76
+ * Minor setup fix for Win32 in tc_all.rb.
77
+
78
+ == 0.7.0 - 25-Apr-2005
79
+ * Scrapped the C implementation for Windows in favor of an OLE + WMI pure Ruby
80
+ approach. See documentation for details.
81
+ * Added an optional lkvm implementation for BSD users. This is automatically
82
+ used if the /proc filesystem isn't found.
83
+ * Added prusage info for the Solaris version.
84
+ * Added name, eid, euid, gid and guid information for Linux. Thanks go to
85
+ James Hranicky for the patch.
86
+ * Fixed some potential bugs in the Linux version. Thanks go to James
87
+ Hranicky for the spot.
88
+ * Added the 'sys/top' package.
89
+ * ProcTable.fields no longer supports a block form.
90
+ * The BTIME (boot time) information has been removed from the Linux version.
91
+ If you want that information, use sys-uptime instead.
92
+ * The .html and .rd files have been removed. You can generate html on your
93
+ own with rdoc if you like.
94
+ * Some code cleanup on the C side of the house.
95
+ * Most documents made rdoc friendly.
96
+ * Renamed 'install_pure_ruby.rb' to just 'install.rb'.
97
+ * Removed the 'INSTALL' file. Installation instructions are in the README.
98
+ * Some test suite cleanup and reorganization.
99
+ * Moved project to RubyForge.
100
+
101
+ == 0.6.4 - 31-Mar-2004
102
+ * Fixed a bug in the pure Ruby version for Win32. Thanks go to Mark Hudson
103
+ for the spot.
104
+ * Fixed a bug in the C implementation for Win32 where the cmdline and path
105
+ values were sometimes wrong for running processes. Thanks go to Park Heesob
106
+ for the fix.
107
+ * Updated the VERSION constant and removed the VERSION class method in the
108
+ pure Ruby version for Win32.
109
+ * Updated install_pure_ruby.rb and test.rb scripts.
110
+ * Updated warranty information.
111
+ * The extconf.rb script has been revamped. See the INSTALL and README files
112
+ for important changes since the last release.
113
+ * The start ProcInfo struct member on Solaris, HP-UX and FreeBSD is now a
114
+ Time object, not a Fixnum/Bignum.
115
+ * Modified linux.c yet again to make gcc happy when it comes to multi-line
116
+ string literals.
117
+ * Minor change to way process state is handled on HP-UX.
118
+ * Documentation additions and updates, including warranty information.
119
+
120
+ == 0.6.3 - 24-Feb-2004
121
+ * Fixed a bug in the Solaris version where the cmd_args array did not
122
+ necessarily contain data on 2.7 and later. The current patch still
123
+ does not quite fix the problem for 2.6 and earlier but can be easily
124
+ derived manually by parsing the cmdline string.
125
+
126
+ == 0.6.2 - 20-Jan-2004
127
+ * Fixed a small memory leak in the solaris version.
128
+
129
+ == 0.6.1 - 31-Dec-2003
130
+ * Fixed a minor bug in the cmdline field on Linux where a blank character
131
+ was being appended to the end of the field.
132
+ * Fixed a minor annoyance where the windows.rb file was being copied into
133
+ the Ruby lib directory on install.
134
+ * Added a test_memleak.rb file. Currently only supported on Linux and
135
+ only does a file descriptor count check. I plan to expand this to
136
+ other platforms in the future.
137
+ * Minor test suite changes
138
+ * MANIFEST correction and update.
139
+
140
+ == 0.6.0 - 22-Oct-2003
141
+ * Significant API change (and thus, a version jump) - only a
142
+ single argument is now accepted to the ps() method, and only a PID
143
+ (Fixnum) is regarded as a valid argument.
144
+ * Calling ps() with a pid returns a single ProcTable struct (or nil
145
+ if the pid is not found), instead of a one element array.
146
+ * Argument to ps() now works properly on HP-UX and Win32.
147
+ * Removed the '#include <sys/types32.h>' in sunos.h. It wasn't needed
148
+ and you're not supposed to include it directly.
149
+ * Fixed 2.6 compatibility issue with regards to cmdline on Solaris.
150
+ * Removed the ProcStatException completely on Linux. There was no reason
151
+ to fail on a directory read for /proc/xxx/stat. If the read fails
152
+ (meaning the process died in the middle of collecting info for it), it
153
+ is simply ignored.
154
+ * The ttynum bug on HPUX has been fixed. In addition, the return value for
155
+ this field is now a string rather than an int and the field name has
156
+ been changed to "ttydev".
157
+ * The ttynum field has been changed to ttydev on Solaris and HPUX. On
158
+ Solaris, the ttydev is now reported as -1 if there is no associated tty.
159
+ In a future release, Solaris and the other *nix platforms will be changed
160
+ so that ttydev is always a device name (i.e String).
161
+ * Added plain text documentation for all platforms.
162
+ * Some test suite cleanup.
163
+ * Changed .rd2 extension to just '.rd'.
164
+
165
+ == 0.5.2 - 18-Jul-2003
166
+ * Modified cmdline to extend past the traditional 80 character limit on
167
+ Solaris, where possible (Solaris 2.6+ only).
168
+ * Added the cmdline_args and num_args fields on Solaris, which returns
169
+ an array of cmdline arguments and the number of cmdline arguments,
170
+ respectively.
171
+ * Minor modification to fields() method, in addition to warning cleanup
172
+ for Solaris.
173
+ * Changed "defunct" state string to "zombie" for Solaris.
174
+ * Should cleanly compile with -Wall -W now (gcc) on Solaris.
175
+ * Added solaris.txt to doc directory.
176
+ * MANIFEST corrections.
177
+
178
+ == 0.5.1 - 16-Jul-2003
179
+ * Fixed a nasty file descriptor bug in the Linux code, where file descriptors
180
+ were continuously being used up.
181
+ * Added the BTIME (boot time) constant for Linux.
182
+ * Fixed up the test/test.rb file a bit.
183
+ * Added BTIME tests to tc_linux.rb.
184
+
185
+ == 0.5.0 - 11-Jul-200
186
+ * Added HP-UX support!
187
+ * Note that passing PID's or strings as arguments to ps() is not supported
188
+ in the HP-UX version. This functionality will be stripped out of the
189
+ other versions in a future release. See the README file for more details.
190
+ * Removed the VERSION() class method. Use the constant instead.
191
+ * Separated the rd docs from their respective source files. Now in the doc
192
+ directory.
193
+ * Got rid of the interactive html generation in extconf.rb.
194
+ * Changed License to Artistic.
195
+
196
+ == 0.4.3 - 30-May-2003
197
+ * Added a version.h file to store the version number. Modified all of the
198
+ C source files to use that instead of hard coding the version everywhere.
199
+ * Added a generic test.rb script for those without TestUnit installed, or
200
+ just futzing in general. Modified the extconf.rb script to copy this
201
+ instead of writing an inline HERE document.
202
+ * Modified extconf.rb so that it builds with mingw or cygwin. Thanks go to
203
+ Peter Fischer for the spot and patch.
204
+ * Modified test suite to work with TestUnit 0.1.6 or 0.1.8.
205
+
206
+ == 0.4.2 - 14-Apr-2003
207
+ * Added pure Ruby version for Win32 - thanks Park Heesob.
208
+ * Modified extconf.rb file to handle pure Ruby versions.
209
+ * Added install_pure_ruby.rb file, an alternate installation
210
+ script for pure Ruby versions.
211
+
212
+ == 0.4.1 - 31-Mar-2003
213
+ * Added support for Solaris 2.5.x.
214
+ * All exceptions are now a direct subclass of StandardError.
215
+ * Value returned for wchan now more meaningful (2.5.x only for now).
216
+ * Fixed the start, utime and ctime for FreeBSD.
217
+ * Minor fix to FreeBSD test suite.
218
+ * Some changes to extconf.rb.
219
+ * Minor doc changes.
220
+ * Added License and Copyright info.
221
+
222
+ == 0.4.0 - 10-Mar-2003
223
+ * Added MS Windows support (non-cygwin).
224
+ * Added environment information for Linux version.
225
+ * Added real exceptions (type depends on platform).
226
+ * Added a test suite (for those with testunit installed).
227
+ * Removed the sys-uname requirement.
228
+ * Heavily modified the extconf.rb script.
229
+ * Changed "Changelog" to "CHANGES" and "Manifest" to "MANIFEST".
230
+ * Added a VERSION constant and class method.
231
+ * Minor internal directory layout change (put 'os' under 'lib').
232
+ * Changed package name to lower case.
233
+ * Doc changes, including license information.
234
+
235
+ == 0.3.1 - 16-Aug-2002
236
+ * Added a "comm" field to the sunos version. I am going to try to make this a
237
+ common field for all platforms to help reduce RUBY_PLATFORM checking.
238
+ * Fixed the release date for 0.3.0 (was accidentally marked *July*).
239
+ * Added an INSTALL file.
240
+ * Minor documentation change to the sunos.c source file.
241
+
242
+ == 0.3.0 - 11-Aug-2002
243
+ * Added FreeBSD support!
244
+ * Struct name changed to just "ProcTableStruct" to be compliant with future
245
+ versions of Ruby.
246
+ * The ps() function now returns an array of ProcTableStruct's in lvalue context.
247
+ * Fixed the ability to search by process name in Linux.
248
+ * Modified Linux "comm" field to strip parenthesis.
249
+ * Some doc changes/additions.
250
+ * Added Sean Chittenden to the "Acknowledgements" section. Sean provided me
251
+ with access to a FreeBSD box, which is how I was able to provide FreeBSD
252
+ support. Thanks Sean!
253
+
254
+ == 0.2.0 - 19-Jul-2002
255
+ * Added the ability to search by process name.
256
+ * test.rb modified to be cross-platform.
257
+ * Solaris - fixed bug with fname (was accidentally called "name").
258
+
259
+ == 0.1.0 - 2-Jul-2002
260
+ - Initial release.
@@ -0,0 +1,38 @@
1
+ CHANGES
2
+ INSTALL
3
+ MANIFEST
4
+ Rakefile
5
+ sys-proctable.gemspec
6
+
7
+ doc/freebsd.txt
8
+ doc/hpux.txt
9
+ doc/linux.txt
10
+ doc/solaris.txt
11
+ doc/top.txt
12
+ doc/windows.txt
13
+
14
+ example/example_ps.rb
15
+
16
+ ext/extconf.rb
17
+ ext/bsd/bsd.c
18
+ ext/darwin/darwin.c
19
+ ext/freebsd/freebsd.c
20
+ ext/freebsd/freebsd.h
21
+ ext/hpux/hpux.c
22
+ ext/hpux/hpux.h
23
+ ext/version.h
24
+
25
+ lib/sys/top.rb
26
+ lib/sys/linux.rb
27
+ lib/sys/sunos.rb
28
+ lib/sys/windows.rb
29
+
30
+ test/test_sys_proctable_all.rb
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
data/README ADDED
@@ -0,0 +1,137 @@
1
+ = Description
2
+ A Ruby interface for gathering process information.
3
+
4
+ = Prerequisites
5
+ * Ruby 1.8.2 or later
6
+ * Test::Unit 2.x
7
+
8
+ = Supported Platforms
9
+ * Windows NT family (NT, 2000, XP, etc)
10
+ * Linux
11
+ * FreeBSD
12
+ * Solaris 2.8+
13
+ * HP-UX
14
+ * OS X
15
+
16
+ = Installation
17
+ * rake test (optional)
18
+ * rake install
19
+
20
+ = Synopsis
21
+ require 'sys/proctable'
22
+ include Sys
23
+
24
+ # Everything
25
+ ProcTable.ps{ |p|
26
+ puts p.pid.to_s
27
+ puts p.comm
28
+ ...
29
+ }
30
+
31
+ or
32
+
33
+ # Just one process
34
+ s = ProcTable.ps(2123)
35
+ puts s.pid.to_s
36
+ puts s.comm
37
+ ...
38
+
39
+ # Return the results as an array of ProcTableStructs
40
+ a = ProcTable.ps
41
+ a.each do |p|
42
+ puts a.pid
43
+ ...
44
+ end
45
+
46
+ = Notes
47
+ Windows users may pass a host name as a second argument to get process
48
+ information from a different host. This relies on the WMI service running.
49
+
50
+ If you're building C source code, the ts_all.rb file is autogenerated for
51
+ you.
52
+
53
+ = Known Issues
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.
64
+
65
+ === Solaris
66
+ The cmdline member on Solaris is limited to 80 characters unless you (or
67
+ your program) own the process. This is a Solaris design flaw/feature.
68
+
69
+ === OS X
70
+ At the moment you do not get the full command line string. The code required
71
+ to get this information is obnoxious and I don't have any compelling desire
72
+ to add it. However, if you're willing to submit a patch I'll accept it.
73
+
74
+ You can find a good starting point with the OS X code found in Dan Urist's
75
+ Proc::ProcessTable module. You can find that module on CPAN. Point your
76
+ browser at http://search.cpan.org.
77
+
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
+ === Thread Safety
87
+ I am not currently using a thread-safe version of readdir(). I am not
88
+ especially concerned about it either. If you are trying to read information
89
+ out of /proc from different threads at the same time there is something
90
+ seriously wrong with your code logic. Using readdir_r() still won't solve
91
+ all potential thread safety issues anyway.
92
+
93
+ = Future Plans
94
+ Research has indicated that the kvm approach is less favored than a sysctl
95
+ approach on BSD variants. I will try to add this interface in a future
96
+ release.
97
+
98
+ = Acknowledgements
99
+ This library is largely based on the Perl module Proc::ProcessTable by
100
+ Dan Urist. Many ideas, as well as large chunks of code, were taken
101
+ from his work. So, a big THANK YOU goes out to Dan Urist.
102
+
103
+ A big thanks also goes out to Mike Hall who was very helpful with ideas,
104
+ logic and testing.
105
+
106
+ Thanks also go to Sean Chittenden for providing an account on one of his
107
+ FreeBSD machines. This is how the FreeBSD support was (initially) added.
108
+
109
+ Thanks go to James Hranicky for providing a patch that grabs name, eid,
110
+ euid, gid and guid info in the Linux version, along with some general
111
+ debugging help.
112
+
113
+ Finally I'd like to thank all the folks who have submitted bug reports
114
+ and/or patches.
115
+
116
+ = Help Wanted
117
+ I do not have access to all platforms. There are a few other major platforms
118
+ out there, namely AIX, OpenBSD, and IRIX, among others, that I would
119
+ like to see ports for. There are two ways you can help - either submit code
120
+ for your particular platform or give me an account on your platform so I can
121
+ develop on it.
122
+
123
+ = More documentation
124
+ See the documentation under the 'doc' directory for more information,
125
+ including platform specific notes and issues.
126
+
127
+ = License
128
+ Ruby's
129
+
130
+ = Copyright
131
+ (C) 2003-2009 Daniel J. Berger
132
+ All Rights Reserved.
133
+
134
+ = Author
135
+ Daniel J. Berger
136
+ djberg96 at nospam at gmail dot com
137
+ imperator on IRC (Freenode)
@@ -0,0 +1,91 @@
1
+ = Description
2
+ sys-proctable
3
+
4
+ A Ruby interface to the 'ps' command. This is a C extension, not parsed
5
+ output. For FreeBSD, data is read directly out of the /proc filesystem if
6
+ readable. Otherwise, a kvm approach is used.
7
+
8
+ = Synopsis
9
+ require 'sys/proctable'
10
+ include Sys
11
+
12
+ # Everything
13
+ ProcTable.ps{ |p|
14
+ puts p.pid.to_s
15
+ puts p.comm
16
+ ...
17
+ }
18
+
19
+ or
20
+
21
+ # Just one process
22
+ p = ProcTable.ps(2123)
23
+ puts p.pid.to_s
24
+ puts p.comm
25
+ ...
26
+
27
+ or
28
+
29
+ # Return the results as an array of ProcTableStructs
30
+ a = ProcTable.ps()
31
+ a.each do |p|
32
+ puts a.pid
33
+ ...
34
+ end
35
+
36
+ = Constants
37
+ VERSION
38
+ Returns the current version number for this package (as a string).
39
+
40
+ = Class Methods
41
+ ProcTable.fields
42
+ Returns an array of fields available on the current OS.
43
+
44
+ ProcTable.ps(pid = nil)
45
+ ProcTable.ps{ |s| ... }
46
+ If no pid's or processes are included as arguments, in block form it
47
+ returns a struct of type ProcTableStruct for every process in the proc
48
+ table. Otherwise it returns an array of ProcTableStruct's.
49
+
50
+ If a pid argument is provided, a single ProcTable struct is returned, or
51
+ nil if the pid is not found.
52
+
53
+ = Exception Classes
54
+ ProcTable::Error < StandardError
55
+ Raised if the /proc field is unreadable and/or unmounted.
56
+
57
+ = Supported fields
58
+ You can view the supported fields with the "fields()" class method.
59
+
60
+ = Future Plans
61
+ Add a pure-ruby version as an alternative
62
+ Add support for other *BSD flavors
63
+ Add ttydev info
64
+ Add a sysctl version
65
+
66
+ = Known Bugs
67
+ The kvm version for FreeBSD 5.x does not support all of the fields that
68
+ the 4.x version supports.
69
+
70
+ If you find any other bugs please log them on the project
71
+ page at http://www.rubyforge.org/projects/sysutils
72
+
73
+ = License
74
+ Ruby's
75
+
76
+ = Copyright
77
+ (C) 2003-2009 Daniel J. Berger
78
+ All Rights Reserved
79
+
80
+ = Warranty
81
+ This package is provided "as is" and without any express or
82
+ implied warranties, including, without limitation, the implied
83
+ warranties of merchantability and fitness for a particular purpose
84
+
85
+ = Author
86
+ Daniel J. Berger
87
+ djberg96 at nospam at gmail dot com
88
+ imperator on IRC (Freenode)
89
+
90
+ = See Also
91
+ ps, proc
@@ -0,0 +1,50 @@
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
+ include Sys
11
+
12
+ Top.top(5).each{ |ps|
13
+ p ps
14
+ }
15
+
16
+ = Constants
17
+ VERSION
18
+ Returns the version number of this package as a String.
19
+
20
+ = Class Methods
21
+ Top.top(number=10, field="pctcpu")
22
+ Returns an array of ProcTableStruct's. The size of the array (i.e. the
23
+ number of processes) that it returns is based on +number+, and sorted by
24
+ +pctcpu+. By default, the size and field values are 10 and "pctcpu",
25
+ respectively.
26
+
27
+ = Notes
28
+ Not all fields are available on all platforms. Please check your
29
+ platform specific documentation for which fields are available.
30
+
31
+ = Bugs
32
+ None that I'm aware of. Please log bug reports on the project page at
33
+ http://www.rubyforge.org/projects/sysutils
34
+
35
+ = License
36
+ Ruby's
37
+
38
+ = Copyright
39
+ (C) 2004-2009 Daniel J. Berger
40
+ All Rights Reserved.
41
+
42
+ = Warranty
43
+ This package is provided "as is" and without any express or
44
+ implied warranties, including, without limitation, the implied
45
+ warranties of merchantability and fitness for a particular purpose.
46
+
47
+ = Author
48
+ Daniel J. Berger
49
+ djberg96 at nospam at gmail dot com
50
+ imperator on IRC (Freenode)
@@ -0,0 +1,301 @@
1
+ /**********************************************************************
2
+ * bsd.c
3
+ *
4
+ * This is a generic kvm interface used by OpenBSD and NetBSD by
5
+ * default, and by FreeBSD if /proc isn't mounted.
6
+ *
7
+ * It may also work on Solaris, but will probably _not_ work on OS X
8
+ * because they've phased out /dev/mem and /dev/kmem.
9
+ **********************************************************************/
10
+ #include "ruby.h"
11
+ #include "version.h"
12
+ #include <kvm.h>
13
+ #include <sys/param.h>
14
+ #include <sys/stat.h>
15
+ #include <sys/sysctl.h>
16
+ #include <sys/types.h>
17
+ #include <sys/user.h>
18
+
19
+ VALUE cProcTableError, sProcStruct;
20
+
21
+ char* fields[] = {
22
+ "pid","ppid","pgid","ruid",
23
+ "rgid","comm","state","pctcpu","oncpu","ttynum","ttydev","wmesg",
24
+ "time", "priority","usrpri","nice","cmdline","start",
25
+ "maxrss","ixrss","idrss","isrss","minflt","majflt","nswap",
26
+ "inblock","oublock","msgsnd","msgrcv","nsignals","nvcsw","nivcsw",
27
+ "utime","stime"
28
+ };
29
+
30
+ /*
31
+ * call-seq:
32
+ * ProcTable.ps(pid=nil)
33
+ * ProcTable.ps(pid=nil){ |ps| ... }
34
+ *
35
+ * In block form, yields a ProcTableStruct for each process entry that you
36
+ * have rights to. This method returns an array of ProcTableStruct's in
37
+ * non-block form.
38
+ *
39
+ * If a +pid+ is provided, then only a single ProcTableStruct is yielded or
40
+ * returned, or nil if no process information is found for that +pid+.
41
+ */
42
+ static VALUE pt_ps(int argc, VALUE* argv, VALUE klass){
43
+ kvm_t *kd;
44
+ char errbuf[_POSIX2_LINE_MAX];
45
+ char cmdline[_POSIX_ARG_MAX+1];
46
+ char state[8];
47
+ char** args = malloc(sizeof(char*));
48
+ struct kinfo_proc* procs;
49
+ int count; /* Holds total number of processes */
50
+ int i = 0;
51
+ VALUE v_pid, v_tty_num, v_tty_dev, v_start_time;
52
+ VALUE v_pstruct = Qnil;
53
+ VALUE v_array = Qnil;
54
+
55
+ rb_scan_args(argc, argv, "01", &v_pid);
56
+
57
+ if(!rb_block_given_p())
58
+ v_array = rb_ary_new();
59
+
60
+ // Open the kvm interface, get a descriptor
61
+ if ((kd = kvm_open(NULL, NULL, NULL, 0, errbuf)) == NULL)
62
+ rb_raise(cProcTableError, errbuf);
63
+
64
+ // Get the list of processes
65
+ if ((procs = kvm_getprocs(kd, KERN_PROC_ALL, 0, &count)) == NULL) {
66
+ strcpy(errbuf,kvm_geterr(kd));
67
+ kvm_close(kd);
68
+ rb_raise(cProcTableError, errbuf);
69
+ }
70
+
71
+ for(i=0; i<count; i++){
72
+ // Reset some variables
73
+ v_tty_num = Qnil;
74
+ v_tty_dev = Qnil;
75
+ v_start_time = Qnil;
76
+
77
+ // If a PID is provided, skip unless the PID matches
78
+ if(!NIL_P(v_pid)){
79
+ #ifdef HAVE_ST_KP_PROC
80
+ if(procs[i].kp_proc.p_pid != NUM2INT(v_pid))
81
+ continue;
82
+ #else
83
+ if(procs[i].ki_pid != NUM2INT(v_pid))
84
+ continue;
85
+ #endif
86
+ }
87
+
88
+ // Get the command line arguments for the process
89
+ cmdline[0] = '\0';
90
+ args = kvm_getargv(kd, (const struct kinfo_proc *)&procs[i], 0);
91
+ if(args){
92
+ int j = 0;
93
+ while (args[j] && strlen(cmdline) <= _POSIX_ARG_MAX) {
94
+ strcat(cmdline, args[j]);
95
+ strcat(cmdline, " ");
96
+ j++;
97
+ }
98
+ }
99
+
100
+ // Get the start time of the process
101
+ v_start_time = rb_time_new(
102
+ #ifdef HAVE_ST_E_STATS
103
+ procs[i].kp_eproc.e_stats.p_start.tv_sec,
104
+ procs[i].kp_eproc.e_stats.p_start.tv_usec
105
+ #else
106
+ 0,0
107
+ #endif
108
+ );
109
+
110
+ // Get the state of the process
111
+ #ifdef HAVE_ST_KP_PROC
112
+ switch(procs[i].kp_proc.p_stat)
113
+ #else
114
+ switch(procs[i].ki_stat)
115
+ #endif
116
+ {
117
+ case SIDL:
118
+ strcpy(state, "idle");
119
+ break;
120
+ case SRUN:
121
+ strcpy(state, "run");
122
+ break;
123
+ case SSLEEP:
124
+ strcpy(state, "sleep");
125
+ break;
126
+ case SSTOP:
127
+ strcpy(state, "stop");
128
+ break;
129
+ case SZOMB:
130
+ strcpy(state, "zombie");
131
+ break;
132
+ default:
133
+ strcpy(state, "unknown");
134
+ break;
135
+ }
136
+
137
+ // Get ttynum and ttydev. If ttynum is -1, there is no tty
138
+ #ifdef HAVE_ST_KP_EPROC
139
+ v_tty_num = INT2FIX(procs[i].kp_eproc.e_tdev),
140
+ v_tty_dev = rb_str_new2(devname(procs[i].kp_eproc.e_tdev, S_IFCHR));
141
+ #elif HAVE_ST_U_KPROC
142
+ v_tty_num = INT2FIX(procs[i].u_kproc.ki_tdev),
143
+ v_tty_dev = rb_str_new2(devname(procs[i].u_kproc.ki_tdev, S_IFCHR));
144
+ #else
145
+ v_tty_num = INT2FIX(procs[i].ki_tdev),
146
+ v_tty_dev = rb_str_new2(devname(procs[i].ki_tdev, S_IFCHR));
147
+ #endif
148
+
149
+ #ifdef HAVE_ST_KP_PROC
150
+ v_pstruct = rb_struct_new(
151
+ sProcStruct,
152
+ INT2FIX(procs[i].kp_proc.p_pid),
153
+ INT2FIX(procs[i].kp_eproc.e_ppid),
154
+ INT2FIX(procs[i].kp_eproc.e_pgid),
155
+ INT2FIX(procs[i].kp_eproc.e_pcred.p_ruid),
156
+ INT2FIX(procs[i].kp_eproc.e_pcred.p_rgid),
157
+ rb_str_new2(procs[i].kp_proc.p_comm),
158
+ rb_str_new2(state),
159
+ rb_float_new(procs[i].kp_proc.p_pctcpu),
160
+ #ifdef HAVE_ST_P_ONCPU
161
+ INT2FIX(procs[i].kp_proc.p_oncpu),
162
+ #else
163
+ Qnil,
164
+ #endif
165
+ v_tty_num,
166
+ v_tty_dev,
167
+ rb_str_new2(procs[i].kp_eproc.e_wmesg),
168
+ #ifdef HAVE_ST_P_RUNTIME
169
+ INT2FIX(procs[i].kp_proc.p_runtime/1000000),
170
+ #else
171
+ Qnil,
172
+ #endif
173
+ INT2FIX(procs[i].kp_proc.p_priority),
174
+ INT2FIX(procs[i].kp_proc.p_usrpri),
175
+ INT2FIX(procs[i].kp_proc.p_nice),
176
+ rb_str_new2(cmdline),
177
+ v_start_time,
178
+ #ifdef HAVE_ST_E_STATS
179
+ LONG2NUM(procs[i].kp_eproc.e_stats.p_ru.ru_maxrss),
180
+ LONG2NUM(procs[i].kp_eproc.e_stats.p_ru.ru_ixrss),
181
+ LONG2NUM(procs[i].kp_eproc.e_stats.p_ru.ru_idrss),
182
+ LONG2NUM(procs[i].kp_eproc.e_stats.p_ru.ru_isrss),
183
+ LONG2NUM(procs[i].kp_eproc.e_stats.p_ru.ru_minflt),
184
+ LONG2NUM(procs[i].kp_eproc.e_stats.p_ru.ru_majflt),
185
+ LONG2NUM(procs[i].kp_eproc.e_stats.p_ru.ru_nswap),
186
+ LONG2NUM(procs[i].kp_eproc.e_stats.p_ru.ru_inblock),
187
+ LONG2NUM(procs[i].kp_eproc.e_stats.p_ru.ru_oublock),
188
+ LONG2NUM(procs[i].kp_eproc.e_stats.p_ru.ru_msgsnd),
189
+ LONG2NUM(procs[i].kp_eproc.e_stats.p_ru.ru_msgrcv),
190
+ LONG2NUM(procs[i].kp_eproc.e_stats.p_ru.ru_nsignals),
191
+ LONG2NUM(procs[i].kp_eproc.e_stats.p_ru.ru_nvcsw),
192
+ LONG2NUM(procs[i].kp_eproc.e_stats.p_ru.ru_nivcsw),
193
+ LONG2NUM(procs[i].kp_eproc.e_stats.p_ru.ru_utime.tv_sec),
194
+ LONG2NUM(procs[i].kp_eproc.e_stats.p_ru.ru_stime.tv_sec)
195
+ #else
196
+ Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil,
197
+ Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil
198
+ #endif
199
+ );
200
+ #else
201
+ v_pstruct = rb_struct_new(
202
+ sProcStruct,
203
+ INT2FIX(procs[i].ki_pid),
204
+ INT2FIX(procs[i].ki_ppid),
205
+ INT2FIX(procs[i].ki_pgid),
206
+ INT2FIX(procs[i].ki_ruid),
207
+ INT2FIX(procs[i].ki_rgid),
208
+ rb_str_new2(procs[i].ki_ocomm),
209
+ rb_str_new2(state),
210
+ rb_float_new(procs[i].ki_pctcpu),
211
+ INT2FIX(procs[i].ki_oncpu),
212
+ v_tty_num,
213
+ v_tty_dev,
214
+ rb_str_new2(procs[i].ki_wmesg),
215
+ INT2FIX(procs[i].ki_runtime/1000000),
216
+ INT2FIX(procs[i].ki_pri.pri_level),
217
+ INT2FIX(procs[i].ki_pri.pri_user),
218
+ INT2FIX(procs[i].ki_nice),
219
+ rb_str_new2(cmdline),
220
+ v_start_time,
221
+ Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil,
222
+ Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil
223
+ );
224
+ #endif
225
+
226
+ OBJ_FREEZE(v_pstruct); /* Read-only data */
227
+
228
+ if(rb_block_given_p())
229
+ rb_yield(v_pstruct);
230
+ else
231
+ rb_ary_push(v_array, v_pstruct);
232
+ }
233
+
234
+ free(args);
235
+
236
+ if(kd)
237
+ kvm_close(kd);
238
+
239
+ if(!NIL_P(v_pid))
240
+ return v_pstruct;
241
+
242
+ return v_array; // Nil if block given
243
+ }
244
+
245
+ /*
246
+ * call-seq:
247
+ * ProcTable.fields
248
+ *
249
+ * Returns an array of fields that each ProcTableStruct will contain. This
250
+ * may be useful if you want to know in advance what fields are available
251
+ * without having to perform at least one read of the /proc table.
252
+ */
253
+ static VALUE pt_fields(VALUE klass){
254
+ VALUE v_array = rb_ary_new();
255
+ int size = sizeof(fields) / sizeof(fields[0]);
256
+ int i;
257
+
258
+ for(i = 0; i < size; i++)
259
+ rb_ary_push(v_array, rb_str_new2(fields[i]));
260
+
261
+ return v_array;
262
+ }
263
+
264
+ /*
265
+ * A Ruby interface for gathering process table information.
266
+ */
267
+ void Init_proctable(){
268
+ VALUE mSys, cProcTable;
269
+
270
+ /* The Sys module serves as a namespace only */
271
+ mSys = rb_define_module("Sys");
272
+
273
+ /* The ProcTable class encapsulates process table information */
274
+ cProcTable = rb_define_class_under(mSys, "ProcTable", rb_cObject);
275
+
276
+ /* The error typically raised if any of the ProcTable methods fail */
277
+ cProcTableError = rb_define_class_under(cProcTable, "Error", rb_cObject);
278
+
279
+ /* Singleton Methods */
280
+
281
+ rb_define_singleton_method(cProcTable, "ps", pt_ps, -1);
282
+ rb_define_singleton_method(cProcTable, "fields", pt_fields, 0);
283
+
284
+ /* There is no constructor */
285
+ rb_funcall(cProcTable, rb_intern("private_class_method"), 1, ID2SYM(rb_intern("new")));
286
+
287
+ /* Constants */
288
+
289
+ /* 0.8.0: The version of the sys-proctable library */
290
+ rb_define_const(cProcTable, "VERSION", rb_str_new2(SYS_PROCTABLE_VERSION));
291
+
292
+ /* Structures */
293
+
294
+ sProcStruct = rb_struct_define("ProcTableStruct","pid","ppid","pgid","ruid",
295
+ "rgid","comm","state","pctcpu","oncpu","ttynum","ttydev","wmesg",
296
+ "time", "priority","usrpri","nice","cmdline","start",
297
+ "maxrss","ixrss","idrss","isrss","minflt","majflt","nswap",
298
+ "inblock","oublock","msgsnd","msgrcv","nsignals","nvcsw","nivcsw",
299
+ "utime","stime", NULL
300
+ );
301
+ }
@@ -0,0 +1,78 @@
1
+ #############################################################################
2
+ # Installation script for sys-proctable.
3
+ #
4
+ # By running this file, it is assumed that you want a C extension, and not
5
+ # a pure Ruby version. If you want a pure Ruby version (and you're on a
6
+ # platform for which it's supported), run install.rb instead.
7
+ #############################################################################
8
+ require 'mkmf'
9
+ require 'fileutils'
10
+ require 'rbconfig'
11
+
12
+ c_file = nil
13
+ h_file = nil
14
+
15
+ ########################################################################
16
+ # Ruby 1.8.3 and later mandates the use of rb_pid_t over pid_t because
17
+ # some libraries define their own pid_t. So, we check for that.
18
+ ########################################################################
19
+ have_type('rb_pid_t', 'ruby.h')
20
+
21
+ ##########################################################################
22
+ # Determine appropriate source files based on platform. Also, check for
23
+ # certain header files and/or libraries on some platforms.
24
+ #
25
+ # FreeBSD has its own source file if /proc is mounted and contains data.
26
+ # Otherwise it uses the kvm interface. All other BSD platforms always use
27
+ # the kvm interface.
28
+ ##########################################################################
29
+ case Config::CONFIG['host_os']
30
+ when /hpux/i
31
+ c_file = 'hpux/hpux.c'
32
+ h_file = 'hpux/hpux.h'
33
+ when /bsd/i
34
+ if Config::CONFIG['host_os'].match('freebsd') && Dir['/proc/*'].length > 0
35
+ c_file = 'freebsd/freebsd.c'
36
+ h_file = 'freebsd/freebsd.h'
37
+ else
38
+ have_library('kvm')
39
+ have_func('kvm_openfiles')
40
+ have_struct_member('struct kinfo_proc', 'kp_proc', 'sys/user.h')
41
+ have_struct_member('struct kinfo_proc', 'kp_eproc', 'sys/user.h')
42
+ have_struct_member('struct kinfo_proc', 'u_kproc', 'sys/user.h')
43
+ have_struct_member('struct eproc', 'e_stats', 'sys/sysctl.h')
44
+ have_struct_member('struct eproc', 'p_oncpu', 'sys/sysctl.h')
45
+ have_struct_member('struct eproc', 'p_runtime', 'sys/sysctl.h')
46
+ c_file = 'bsd/bsd.c'
47
+ end
48
+ when /darwin/i
49
+ c_file = 'darwin/darwin.c'
50
+ when /windows|mswin|cygwin|mingw|dos|linux|sunos|solaris/i
51
+ STDERR.puts "Use the 'rake install' task to install pure Ruby versions"
52
+ exit
53
+ else
54
+ STDERR.puts 'This platform not currently supported. Exiting...'
55
+ exit
56
+ end
57
+
58
+ #####################################################################
59
+ # Move the '.rb' files under 'lib/sys/' to '.orig' to prevent
60
+ # mkmf from installing them during the 'make install' phase.
61
+ #####################################################################
62
+ Dir.chdir("../lib/sys"){
63
+ Dir["*.rb"].each{ |file|
64
+ next if file == 'top.rb'
65
+ File.rename(file, File.basename(file, '.rb') + '.orig')
66
+ }
67
+ }
68
+
69
+ ########################################################################
70
+ # Copy or link files to current directory for create_makefile to work.
71
+ ########################################################################
72
+ File.delete('proctable.c') rescue nil
73
+ File.delete(File.basename(h_file)) rescue nil
74
+
75
+ FileUtils.cp(c_file, 'proctable.c')
76
+ FileUtils.cp(h_file, File.basename(h_file)) if h_file
77
+
78
+ create_makefile('sys/proctable')
@@ -0,0 +1,2 @@
1
+ /* version.h - stores the version number for all platforms (that use C) */
2
+ #define SYS_PROCTABLE_VERSION "0.8.0"
@@ -0,0 +1,35 @@
1
+ require 'sys/proctable'
2
+ require 'rbconfig'
3
+
4
+ # The Sys module serves as a namespace only
5
+ module Sys
6
+
7
+ # The Top class serves as a toplevel name for the 'top' method.
8
+ class Top
9
+
10
+ # The version of the sys-top library
11
+ VERSION = '1.0.2'
12
+
13
+ # Returns an array of Struct::ProcTableStruct elements containing up
14
+ # to +num+ elements, sorted by +field+. The default number of elements
15
+ # is 10, while the default field is 'pctcpu'.
16
+ #
17
+ # Exception: the default sort field is 'pid' on Linux and Windows.
18
+ #
19
+ def self.top(num=10, field='pctcpu')
20
+ field = field.to_s if field.is_a?(Symbol)
21
+
22
+ # Sort by pid on Windows by default
23
+ if Config::CONFIG['host_os'].match('mswin') && field == 'pctcpu'
24
+ field = 'pid'
25
+ end
26
+
27
+ # Linux does not have a pctcpu field yet
28
+ if Config::CONFIG['host_os'].match('linux') && field == 'pctcpu'
29
+ field = 'pid'
30
+ end
31
+
32
+ Sys::ProcTable.ps.sort_by{ |obj| obj.send(field) || '' }[0..num-1]
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,80 @@
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 'rbconfig'
13
+ require 'test/test_sys_top'
14
+ include Sys
15
+
16
+ class TC_ProcTable_All < Test::Unit::TestCase
17
+ def self.startup
18
+ @@windows = Config::CONFIG['host_os'].match('mswin')
19
+ end
20
+
21
+ def setup
22
+ @pid = @@windows ? 0 : 1
23
+ end
24
+
25
+ def test_version
26
+ assert_equal('0.8.0', ProcTable::VERSION)
27
+ end
28
+
29
+ def test_fields
30
+ assert_respond_to(ProcTable, :fields)
31
+ assert_nothing_raised{ ProcTable.fields }
32
+ assert_kind_of(Array, ProcTable.fields)
33
+ assert_kind_of(String, ProcTable.fields.first)
34
+ end
35
+
36
+ def test_ps
37
+ assert_respond_to(ProcTable, :ps)
38
+ assert_nothing_raised{ ProcTable.ps }
39
+ assert_nothing_raised{ ProcTable.ps{} }
40
+ end
41
+
42
+ def test_ps_with_pid
43
+ assert_nothing_raised{ ProcTable.ps(0) }
44
+ end
45
+
46
+ def test_ps_with_explicit_nil
47
+ assert_nothing_raised{ ProcTable.ps(nil) }
48
+ assert_kind_of(Array, ProcTable.ps(nil))
49
+ end
50
+
51
+ def test_ps_return_value
52
+ assert_kind_of(Array, ProcTable.ps)
53
+ assert_kind_of(Struct::ProcTableStruct, ProcTable.ps(@pid))
54
+ assert_equal(nil, ProcTable.ps(999999999))
55
+ assert_equal(nil, ProcTable.ps(999999999){})
56
+ assert_equal(nil, ProcTable.ps{})
57
+ end
58
+
59
+ def test_ps_returned_struct_is_frozen
60
+ assert_true(ProcTable.ps.first.frozen?)
61
+ end
62
+
63
+ def test_ps_expected_errors
64
+ assert_raises(TypeError){ ProcTable.ps('vim') }
65
+ omit_if(@@windows, 'ArgumentError check skipped on MS Windows')
66
+ assert_raises(ArgumentError){ ProcTable.ps(0, 'localhost') }
67
+ end
68
+
69
+ def test_new_not_allowed
70
+ assert_raise(NoMethodError){ Sys::ProcTable.new }
71
+ end
72
+
73
+ def teardown
74
+ @pid = nil
75
+ end
76
+
77
+ def self.teardown
78
+ @@windows = nil
79
+ end
80
+ end
@@ -0,0 +1,211 @@
1
+ ################################################################
2
+ # test_sys_proctable_kvm.rb
3
+ #
4
+ # Test suite for the BSD specific version of the kvm interface.
5
+ ################################################################
6
+ require 'rubygems'
7
+ gem 'test-unit'
8
+
9
+ require 'test/unit'
10
+ require 'sys/proctable'
11
+ require 'test/test_sys_proctable_all'
12
+ include Sys
13
+
14
+ class TC_Sys_ProcTable_Kvm < Test::Unit::TestCase
15
+ def self.startup
16
+ @@fields = %w/
17
+ pid ppid pgid ruid rgid comm state pctcpu oncpu ttynum ttydev
18
+ wmesg time priority usrpri nice cmdline start
19
+ maxrss ixrss idrss isrss minflt majflt nswap inblock oublock
20
+ msgsnd msgrcv nsignals nvcsw nivcsw utime stime
21
+ /
22
+ end
23
+
24
+ def setup
25
+ @ptable = ProcTable.ps.last
26
+ end
27
+
28
+ def test_fields
29
+ assert_respond_to(ProcTable, :fields)
30
+ assert_kind_of(Array, ProcTable.fields)
31
+ assert_equal(@@fields, ProcTable.fields)
32
+ end
33
+
34
+ def test_pid
35
+ assert_respond_to(@ptable, :pid)
36
+ assert_kind_of(Fixnum, @ptable.pid)
37
+ end
38
+
39
+ def test_ppid
40
+ assert_respond_to(@ptable, :ppid)
41
+ assert_kind_of(Fixnum, @ptable.ppid)
42
+ end
43
+
44
+ def test_pgid
45
+ assert_respond_to(@ptable, :pgid)
46
+ assert_kind_of(Fixnum, @ptable.pgid)
47
+ end
48
+
49
+ def test_ruid
50
+ assert_respond_to(@ptable, :ruid)
51
+ assert_kind_of(Fixnum, @ptable.ruid)
52
+ end
53
+
54
+ def test_rgid
55
+ assert_respond_to(@ptable, :rgid)
56
+ assert_kind_of(Fixnum, @ptable.rgid)
57
+ end
58
+
59
+ def test_comm
60
+ assert_respond_to(@ptable, :comm)
61
+ assert_kind_of(String, @ptable.comm)
62
+ end
63
+
64
+ def test_state
65
+ assert_respond_to(@ptable, :state)
66
+ assert_kind_of(String, @ptable.state)
67
+ end
68
+
69
+ def test_pctcpu
70
+ assert_respond_to(@ptable, :pctcpu)
71
+ assert_kind_of(Float, @ptable.pctcpu)
72
+ end
73
+
74
+ def test_oncpu
75
+ assert_respond_to(@ptable, :oncpu)
76
+ assert_kind_of(Fixnum, @ptable.oncpu)
77
+ end
78
+
79
+ def test_ttynum
80
+ assert_respond_to(@ptable, :ttynum)
81
+ assert_kind_of(Fixnum, @ptable.ttynum)
82
+ end
83
+
84
+ def test_ttydev
85
+ assert_respond_to(@ptable, :ttydev)
86
+ assert_kind_of(String, @ptable.ttydev)
87
+ end
88
+
89
+ def test_wmesg
90
+ assert_respond_to(@ptable, :wmesg)
91
+ assert_kind_of(String, @ptable.wmesg)
92
+ end
93
+
94
+ def test_time
95
+ assert_respond_to(@ptable, :time)
96
+ assert_kind_of(Fixnum, @ptable.time)
97
+ end
98
+
99
+ def test_priority
100
+ assert_respond_to(@ptable, :priority)
101
+ assert_kind_of(Fixnum, @ptable.priority)
102
+ end
103
+
104
+ def test_usrpri
105
+ assert_respond_to(@ptable, :usrpri)
106
+ assert_kind_of(Fixnum, @ptable.usrpri)
107
+ end
108
+
109
+ def test_nice
110
+ assert_respond_to(@ptable, :nice)
111
+ assert_kind_of(Fixnum, @ptable.nice)
112
+ end
113
+
114
+ def test_cmdline
115
+ assert_respond_to(@ptable, :cmdline)
116
+ assert_kind_of(String, @ptable.cmdline)
117
+ end
118
+
119
+ def test_start
120
+ assert_respond_to(@ptable, :start)
121
+ assert_kind_of(Time, @ptable.start)
122
+ end
123
+
124
+ def test_maxrss
125
+ assert_respond_to(@ptable, :maxrss)
126
+ assert_true(@ptable.maxrss.kind_of?(Fixnum) || @ptable.maxrss.nil?)
127
+ end
128
+
129
+ def test_ixrss
130
+ assert_respond_to(@ptable, :ixrss)
131
+ assert_true(@ptable.ixrss.kind_of?(Fixnum) || @ptable.ixrss.nil?)
132
+ end
133
+
134
+ def test_idrss
135
+ assert_respond_to(@ptable, :idrss)
136
+ assert_true(@ptable.idrss.kind_of?(Fixnum) || @ptable.idrss.nil?)
137
+ end
138
+
139
+ def test_isrss
140
+ assert_respond_to(@ptable, :isrss)
141
+ assert_true(@ptable.isrss.kind_of?(Fixnum) || @ptable.isrss.nil?)
142
+ end
143
+
144
+ def test_minflt
145
+ assert_respond_to(@ptable, :minflt)
146
+ assert_true(@ptable.minflt.kind_of?(Fixnum) || @ptable.minflt.nil?)
147
+ end
148
+
149
+ def test_majflt
150
+ assert_respond_to(@ptable, :majflt)
151
+ assert_true(@ptable.majflt.kind_of?(Fixnum) || @ptable.majflt.nil?)
152
+ end
153
+
154
+ def test_nswap
155
+ assert_respond_to(@ptable, :nswap)
156
+ assert_true(@ptable.nswap.kind_of?(Fixnum) || @ptable.nswap.nil?)
157
+ end
158
+
159
+ def test_inblock
160
+ assert_respond_to(@ptable, :inblock)
161
+ assert_true(@ptable.inblock.kind_of?(Fixnum) || @ptable.inblock.nil?)
162
+ end
163
+
164
+ def test_oublock
165
+ assert_respond_to(@ptable, :oublock)
166
+ assert_true(@ptable.oublock.kind_of?(Fixnum) || @ptable.oublock.nil?)
167
+ end
168
+
169
+ def test_msgsnd
170
+ assert_respond_to(@ptable, :msgsnd)
171
+ assert_true(@ptable.msgsnd.kind_of?(Fixnum) || @ptable.msgsnd.nil?)
172
+ end
173
+
174
+ def test_msgrcv
175
+ assert_respond_to(@ptable, :msgrcv)
176
+ assert_true(@ptable.msgrcv.kind_of?(Fixnum) || @ptable.msgrcv.nil?)
177
+ end
178
+
179
+ def test_nsignals
180
+ assert_respond_to(@ptable, :nsignals)
181
+ assert_true(@ptable.nsignals.kind_of?(Fixnum) || @ptable.nsignals.nil?)
182
+ end
183
+
184
+ def test_nvcsw
185
+ assert_respond_to(@ptable, :nvcsw)
186
+ assert_true(@ptable.nvcsw.kind_of?(Fixnum) || @ptable.nvcsw.nil?)
187
+ end
188
+
189
+ def test_nivcsw
190
+ assert_respond_to(@ptable, :nivcsw)
191
+ assert_true(@ptable.nivcsw.kind_of?(Fixnum) || @ptable.nivcsw.nil?)
192
+ end
193
+
194
+ def test_utime
195
+ assert_respond_to(@ptable, :utime)
196
+ assert_true(@ptable.utime.kind_of?(Fixnum) || @ptable.utime.nil?)
197
+ end
198
+
199
+ def test_stime
200
+ assert_respond_to(@ptable, :stime)
201
+ assert_true(@ptable.stime.kind_of?(Fixnum) || @ptable.stime.nil?)
202
+ end
203
+
204
+ def teardown
205
+ @ptable = nil
206
+ end
207
+
208
+ def self.shutdown
209
+ @@fields = nil
210
+ end
211
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sys-proctable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.0
5
+ platform: x86-freebsd-7
6
+ authors:
7
+ - Daniel J. Berger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-26 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: test-unit
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.0.2
24
+ version:
25
+ description: An interface for providing process table information
26
+ email: djberg96@gmail.com
27
+ executables: []
28
+
29
+ extensions:
30
+ - ext/extconf.rb
31
+ extra_rdoc_files:
32
+ - CHANGES
33
+ - README
34
+ - MANIFEST
35
+ - doc/top.txt
36
+ - ext/bsd/bsd.c
37
+ files:
38
+ - lib/sys/top.rb
39
+ - test/test_sys_proctable_all.rb
40
+ - test/test_sys_proctable_kvm.rb
41
+ - CHANGES
42
+ - README
43
+ - MANIFEST
44
+ - doc/top.txt
45
+ - ext/bsd/bsd.c
46
+ - ext/extconf.rb
47
+ - ext/version.h
48
+ - doc/freebsd.txt
49
+ has_rdoc: true
50
+ homepage: http://www.rubyforge.org/projects/sysutils
51
+ post_install_message:
52
+ rdoc_options: []
53
+
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ requirements: []
69
+
70
+ rubyforge_project: sysutils
71
+ rubygems_version: 1.3.1
72
+ signing_key:
73
+ specification_version: 2
74
+ summary: An interface for providing process table information
75
+ test_files:
76
+ - test/test_sys_proctable_all.rb
77
+ - test/test_sys_proctable_kvm.rb