sys-proctable 0.8.1-x86-darwin-8 → 0.8.2-x86-darwin-8

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,22 @@
1
+ == 0.9.0 - 14-Oct-2009
2
+ * Changed the license to Artistic 2.0.
3
+ * Fixed a bug in the OS X code where a segfault would occur when an attempt
4
+ was made to gather resource usage information on zombie processes. From
5
+ now on that information is always set to nil for zombie processes. Thanks
6
+ go to Tom Lianza for the spot and Philip Kromer for investigating the
7
+ root cause of the failure.
8
+ * Removed the FreeBSD code that read out of /proc. It was a pain from a
9
+ maintenance point of view, and most FreeBSD installs do not mount /proc
10
+ by default. The FreeBSD platform now uses the same code that the other
11
+ BSD platforms use.
12
+ * Fixed a bug in the BSD code where the ProcTable::Error class had the
13
+ wrong parent class.
14
+ * Some major gemspec updates, including an updated license. The platform
15
+ handling logic is now in the Rakefile in the 'gem' task.
16
+ * Updated the README file to include an additional acknowledgement, a
17
+ license change and some minor formatting changes.
18
+ * The test-unit library was changed from a runtime to a development dependency.
19
+
1
20
  == 0.8.1 - 6-Apr-2009
2
21
  * The Linux and Solaris libraries now handle the possibility of a process
3
22
  terminating in the middle of a read more gracefully. If that happens, they
data/MANIFEST CHANGED
@@ -1,38 +1,30 @@
1
- CHANGES
2
- 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
1
+ * CHANGES
2
+ * MANIFEST
3
+ * Rakefile
4
+ * README
5
+ * sys-proctable.gemspec
6
+ * doc/bsd.txt
7
+ * doc/hpux.txt
8
+ * doc/linux.txt
9
+ * doc/solaris.txt
10
+ * doc/top.txt
11
+ * doc/windows.txt
12
+ * example/example_ps.rb
13
+ * ext/bsd/extconf.rb
14
+ * ext/bsd/sys/proctable.c
15
+ * ext/darwin/extconf.rb
16
+ * ext/darwin/sys/proctable.c
17
+ * ext/hpux/extconf.rb
18
+ * ext/hpux/sys/proctable.c
19
+ * lib/sys/top.rb
20
+ * lib/linux/sys/proctable.rb
21
+ * lib/sunos/sys/proctable.rb
22
+ * lib/windows/sys/proctable.rb
23
+ * test/test_sys_proctable_all.rb
24
+ * test/test_sys_proctable_darwin.rb
25
+ * test/test_sys_proctable_hpux.rb
26
+ * test/test_sys_proctable_bsd.rb
27
+ * test/test_sys_proctable_linux.rb
28
+ * test/test_sys_proctable_sunos.rb
29
+ * test/test_sys_proctable_windows.rb
30
+ * test/test_sys_top.rb
data/README CHANGED
@@ -1,21 +1,30 @@
1
- = Description
1
+ == Description
2
2
  A Ruby interface for gathering process information.
3
3
 
4
- = Prerequisites
4
+ == Prerequisites
5
5
  * Ruby 1.8.2 or later
6
- * Test::Unit 2.x
6
+ * Test::Unit 2.x (development only)
7
7
 
8
- = Supported Platforms
8
+ == Supported Platforms
9
9
  * Windows NT family (NT, 2000, XP, etc)
10
- * Linux
11
- * FreeBSD
12
- * Solaris 2.8+
13
- * HP-UX
14
- * OS X
10
+ * Linux 2.6+
11
+ * BSD (various flavors)
12
+ * Solaris 8+
13
+ * HP-UX 10+
14
+ * OS X 10.4+
15
15
 
16
- = Installation
17
- * rake test (optional)
18
- * rake install
16
+ == Installation
17
+ === Rubygems
18
+ gem install sys-proctable
19
+
20
+ You may need to specify a platform in some cases. For example:
21
+
22
+ gem install sys-proctable --platform mswin32 # Windows
23
+ gem install sys-proctable --platform sunos # Solaris
24
+ gem install sys-proctalbe --platform linux # Linux
25
+
26
+ === Standard
27
+ rake install
19
28
 
20
29
  = Synopsis
21
30
  require 'sys/proctable'
@@ -43,24 +52,14 @@
43
52
  ...
44
53
  end
45
54
 
46
- = Notes
55
+ == Notes
47
56
  Windows users may pass a host name as a second argument to get process
48
57
  information from a different host. This relies on the WMI service running.
49
58
 
50
- 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.
59
+ == Known Issues
60
+ === BSD
61
+ A kvm interface is used. That means the owner of the process using the
62
+ sys-proctable library needs to be a member of the kvm group (or root).
64
63
 
65
64
  === Solaris
66
65
  The cmdline member on Solaris is limited to 80 characters unless you (or
@@ -75,27 +74,19 @@
75
74
  Proc::ProcessTable module. You can find that module on CPAN. Point your
76
75
  browser at http://search.cpan.org.
77
76
 
78
- === Misc
79
- If you build your library as a C extension (which is what will happen if
80
- you run the 'build', 'test', or 'install' Rake tasks), then the .rb files
81
- file under 'lib/sys/' are renamed to '.orig', except top.rb. This is
82
- necessary to prevent mkmf from installing them during a 'make install'.
83
-
84
- The 'clean' Rake task will rename them back to '.rb'.
85
-
86
77
  === Thread Safety
87
- I am not currently using a thread-safe version of readdir(). I am not
88
- especially concerned about it either. If you are trying to read information
78
+ I am not currently using a thread-safe version of readdir(). I am not
79
+ especially concerned about it either. If you are trying to read information
89
80
  out of /proc from different threads at the same time there is something
90
81
  seriously wrong with your code logic. Using readdir_r() still won't solve
91
82
  all potential thread safety issues anyway.
92
83
 
93
- = Future Plans
84
+ == Future Plans
94
85
  Research has indicated that the kvm approach is less favored than a sysctl
95
86
  approach on BSD variants. I will try to add this interface in a future
96
87
  release.
97
88
 
98
- = Acknowledgements
89
+ == Acknowledgements
99
90
  This library is largely based on the Perl module Proc::ProcessTable by
100
91
  Dan Urist. Many ideas, as well as large chunks of code, were taken
101
92
  from his work. So, a big THANK YOU goes out to Dan Urist.
@@ -109,29 +100,27 @@
109
100
  Thanks go to James Hranicky for providing a patch that grabs name, eid,
110
101
  euid, gid and guid info in the Linux version, along with some general
111
102
  debugging help.
103
+
104
+ Thanks go to David Felstead for the original OS X code.
112
105
 
113
106
  Finally I'd like to thank all the folks who have submitted bug reports
114
107
  and/or patches.
115
108
 
116
- = 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.
109
+ == Help Wanted
110
+ I do not have access to all platforms. If your platform is not supported
111
+ then you will need to either submit a patch or give me a remote account
112
+ on a box with a compiler so that I can write the code.
122
113
 
123
- = More documentation
114
+ == More documentation
124
115
  See the documentation under the 'doc' directory for more information,
125
116
  including platform specific notes and issues.
126
117
 
127
- = License
128
- Ruby's
118
+ == License
119
+ Artistic 2.0
129
120
 
130
- = Copyright
121
+ == Copyright
131
122
  (C) 2003-2009 Daniel J. Berger
132
123
  All Rights Reserved.
133
124
 
134
- = Author
125
+ == Author
135
126
  Daniel J. Berger
136
- djberg96 at nospam at gmail dot com
137
- imperator on IRC (Freenode)
data/Rakefile ADDED
@@ -0,0 +1,167 @@
1
+ require 'rake'
2
+ require 'rake/clean'
3
+ require 'rake/testtask'
4
+ require 'rbconfig'
5
+
6
+ desc 'Clean the build files for C versions of sys-proctable'
7
+ task :clean do
8
+ rm_rf('.test-result') if File.exists?('.test-result')
9
+ Dir['*.gem'].each{ |f| File.delete(f) }
10
+
11
+ case Config::CONFIG['host_os']
12
+ when /bsd/i
13
+ dir = 'ext/bsd'
14
+ when /darwin/i
15
+ dir = 'ext/darwin'
16
+ when /hpux/i
17
+ dir = 'ext/hpux'
18
+ end
19
+
20
+ unless Config::CONFIG['host_os'] =~ /win32|mswin|dos|cygwin|mingw|linux|sunos|solaris/i
21
+ Dir.chdir(dir) do
22
+ if Dir['*.o'].length > 0
23
+ sh 'make distclean'
24
+ Dir['sys/proctable.*'].each{ |f| rm(f) if File.extname(f) != '.c' }
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ desc 'Build the sys-proctable library for C versions of sys-proctable'
31
+ task :build => [:clean] do
32
+ case Config::CONFIG['host_os']
33
+ when /bsd/i
34
+ dir = 'ext/bsd'
35
+ when /darwin/i
36
+ dir = 'ext/darwin'
37
+ when /hpux/i
38
+ dir = 'ext/hpux'
39
+ end
40
+
41
+ unless Config::CONFIG['host_os'] =~ /win32|mswin|dos|cygwin|mingw|linux|sunos|solaris/i
42
+ Dir.chdir(dir) do
43
+ ruby 'extconf.rb'
44
+ sh 'make'
45
+ cp 'proctable.' + Config::CONFIG['DLEXT'], 'sys'
46
+ end
47
+ end
48
+ end
49
+
50
+ desc 'Install the sys-proctable library'
51
+ task :install => [:build] do
52
+ file = nil
53
+ dir = File.join(Config::CONFIG['sitelibdir'], 'sys')
54
+
55
+ Dir.mkdir(dir) unless File.exists?(dir)
56
+
57
+ case Config::CONFIG['host_os']
58
+ when /mswin|win32|msdos|cygwin|mingw/i
59
+ file = 'lib/windows/sys/proctable.rb'
60
+ when /linux/i
61
+ file = 'lib/linux/sys/proctable.rb'
62
+ when /sunos|solaris/i
63
+ file = 'lib/sunos/sys/proctable.rb'
64
+ when /bsd/i
65
+ Dir.chdir('ext/bsd'){ sh 'make install' }
66
+ when /darwin/i
67
+ Dir.chdir('ext/darwin'){ sh 'make install' }
68
+ when /hpux/i
69
+ Dir.chdir('ext/hpux'){ sh 'make install' }
70
+ end
71
+
72
+ cp(file, dir, :verbose => true) if file
73
+ end
74
+
75
+ desc 'Uninstall the sys-proctable library'
76
+ task :uninstall do
77
+ case Config::CONFIG['host_os']
78
+ when /win32|mswin|dos|cygwin|mingw|linux|sunos|solaris/i
79
+ dir = File.join(Config::CONFIG['sitelibdir'], 'sys')
80
+ file = File.join(dir, 'proctable.rb')
81
+ else
82
+ dir = File.join(Config::CONFIG['sitearchdir'], 'sys')
83
+ file = File.join(dir, 'proctable.' + Config::CONFIG['DLEXT'])
84
+ end
85
+
86
+ rm(file)
87
+ end
88
+
89
+ desc 'Run the benchmark suite'
90
+ task :bench => [:build] do
91
+ sh "ruby -Ilib benchmarks/bench_ps.rb"
92
+ end
93
+
94
+ desc 'Run the example program'
95
+ task :example => [:build] do
96
+ sh 'ruby -Ilib -Iext examples/example_ps.rb'
97
+ end
98
+
99
+ desc 'Run the test suite'
100
+ Rake::TestTask.new do |t|
101
+ task :test => :build
102
+ t.libs << 'test'
103
+
104
+ case Config::CONFIG['host_os']
105
+ when /mswin|msdos|cygwin|mingw/i
106
+ t.test_files = FileList['test/test_sys_proctable_windows.rb']
107
+ t.libs << 'lib/windows'
108
+ when /linux/i
109
+ t.test_files = FileList['test/test_sys_proctable_linux.rb']
110
+ t.libs << 'lib/linux'
111
+ when /sunos|solaris/i
112
+ t.test_files = FileList['test/test_sys_proctable_sunos.rb']
113
+ t.libs << 'lib/sunos'
114
+ when /darwin/i
115
+ t.libs << 'ext/darwin'
116
+ t.test_files = FileList['test/test_sys_proctable_darwin.rb']
117
+ when /bsd/i
118
+ t.libs << 'ext/bsd'
119
+ t.test_files = FileList['test/test_sys_proctable_bsd.rb']
120
+ when /hpux/i
121
+ t.libs << 'ext/hpux'
122
+ t.test_files = FileList['test/test_sys_proctable_hpux.rb']
123
+ end
124
+ end
125
+
126
+ desc 'Create a gem'
127
+ task :gem do
128
+ spec = eval(IO.read('sys-proctable.gemspec'))
129
+
130
+ case Config::CONFIG['host_os']
131
+ when /bsd/i
132
+ spec.files << 'ext/bsd/sys/proctable.c'
133
+ spec.extra_rdoc_files << 'ext/bsd/sys/proctable.c'
134
+ spec.test_files << 'test/test_sys_proctable_bsd.rb'
135
+ spec.extensions = ['ext/bsd/extconf.rb']
136
+ when /darwin/i
137
+ spec.files << 'ext/darwin/sys/proctable.c'
138
+ spec.extra_rdoc_files << 'ext/darwin/sys/proctable.c'
139
+ spec.test_files << 'test/test_sys_proctable_darwin.rb'
140
+ spec.extensions = ['ext/darwin/extconf.rb']
141
+ when /hpux/i
142
+ spec.files << 'ext/hpux/sys/proctable.c'
143
+ spec.extra_rdoc_files << 'ext/hpux/sys/proctable.c'
144
+ spec.test_files << 'test/test_sys_proctable_hpux.rb'
145
+ spec.extensions = ['ext/hpux/extconf.rb']
146
+ when /linux/i
147
+ spec.require_paths = ['lib', 'lib/linux']
148
+ spec.files += ['lib/linux/sys/proctable.rb']
149
+ spec.test_files << 'test/test_sys_proctable_linux.rb'
150
+ when /sunos|solaris/i
151
+ spec.require_paths = ['lib', 'lib/sunos']
152
+ spec.files += ['lib/sunos/sys/proctable.rb']
153
+ spec.test_files << 'test/test_sys_proctable_sunos.rb'
154
+ when /mswin|win32|dos|cygwin|mingw/i
155
+ spec.require_paths = ['lib', 'lib/windows']
156
+ spec.files += ['lib/windows/sys/proctable.rb']
157
+ spec.test_files << 'test/test_sys_proctable_windows.rb'
158
+ end
159
+
160
+ Gem::Builder.new(spec).build
161
+ end
162
+
163
+ desc 'Install the sys-proctable library as a gem'
164
+ task :install_gem => [:gem] do
165
+ gem_name = Dir['*.gem'].first
166
+ sh "gem install #{gem_name}"
167
+ end
@@ -0,0 +1,21 @@
1
+ ########################################################################
2
+ # bench_ps.rb
3
+ #
4
+ # Benchmark program to show overall speed and compare the block form
5
+ # versus the non-block form. You should run this benchmark via the
6
+ # 'rake bench' Rake task.
7
+ ########################################################################
8
+ require 'benchmark'
9
+ require 'sys/proctable'
10
+
11
+ MAX = 10
12
+
13
+ Benchmark.bm do |bench|
14
+ bench.report("Block form"){
15
+ MAX.times{ Sys::ProcTable.ps{} }
16
+ }
17
+
18
+ bench.report("Non-block form"){
19
+ MAX.times{ Sys::ProcTable.ps }
20
+ }
21
+ end
data/doc/top.txt CHANGED
@@ -7,9 +7,8 @@
7
7
 
8
8
  = Synopsis
9
9
  require "sys/top"
10
- include Sys
11
10
 
12
- Top.top(5).each{ |ps|
11
+ Sys::Top.top(5).each{ |ps|
13
12
  p ps
14
13
  }
15
14
 
@@ -18,7 +17,7 @@ VERSION
18
17
  Returns the version number of this package as a String.
19
18
 
20
19
  = Class Methods
21
- Top.top(number=10, field="pctcpu")
20
+ Sys::Top.top(number=10, field="pctcpu")
22
21
  Returns an array of ProcTableStruct's. The size of the array (i.e. the
23
22
  number of processes) that it returns is based on +number+, and sorted by
24
23
  +pctcpu+. By default, the size and field values are 10 and "pctcpu",
@@ -33,7 +32,7 @@ Top.top(number=10, field="pctcpu")
33
32
  http://www.rubyforge.org/projects/sysutils
34
33
 
35
34
  = License
36
- Ruby's
35
+ Artistic 2.0
37
36
 
38
37
  = Copyright
39
38
  (C) 2004-2009 Daniel J. Berger
@@ -45,6 +44,4 @@ Top.top(number=10, field="pctcpu")
45
44
  warranties of merchantability and fitness for a particular purpose.
46
45
 
47
46
  = Author
48
- Daniel J. Berger
49
- djberg96 at nospam at gmail dot com
50
- imperator on IRC (Freenode)
47
+ Daniel J. Berger
@@ -0,0 +1,20 @@
1
+ #######################################################################
2
+ # example_ps.rb
3
+ #
4
+ # Generic test program that demonstrates the use of ProcTable.ps. You
5
+ # can run this via the 'rake example' task.
6
+ #
7
+ # Modify as you see fit
8
+ #######################################################################
9
+ require 'sys/proctable'
10
+ include Sys
11
+
12
+ puts "VERSION: " + ProcTable::VERSION
13
+ sleep 2
14
+
15
+ ProcTable.ps{ |s|
16
+ ProcTable.fields.each{ |field|
17
+ puts "#{field}: " + s.send(field).to_s
18
+ }
19
+ puts '=' * 30
20
+ }
@@ -0,0 +1,4 @@
1
+ require 'mkmf'
2
+
3
+ have_type('rb_pid_t', 'ruby.h')
4
+ create_makefile('sys/proctable', 'sys')
@@ -1,10 +1,11 @@
1
- /* Mac OS X code for Ruby Sys::ProcTable */
2
- /* Date: 3-Mar-2006 (original submission date) */
3
- /* Author: David Felstead (david.felstead at gmail dot com) */
4
- /* Based on bsd.c by Daniel J. Berger (djberg96 at gmail dot com) */
5
-
1
+ /**********************************************************************
2
+ * Mac OS X code for sys-proctable Ruby library. *
3
+ * *
4
+ * Date: 3-Mar-2006 (original submission date) *
5
+ * Author: David Felstead (david.felstead at gmail dot com) *
6
+ * Based on bsd.c by Daniel J. Berger (djberg96 at gmail dot com) *
7
+ *********************************************************************/
6
8
  #include "ruby.h"
7
- #include "version.h"
8
9
  #include <sys/param.h>
9
10
  #include <sys/stat.h>
10
11
  #include <sys/sysctl.h>
@@ -12,6 +13,8 @@
12
13
  #include <sys/user.h>
13
14
  #include <errno.h>
14
15
 
16
+ #define SYS_PROCTABLE_VERSION "0.9.0"
17
+
15
18
  #define PROC_MIB_LEN 4
16
19
  #define ARGS_MIB_LEN 3
17
20
  #define ARGS_MAX_LEN 4096
@@ -48,41 +51,40 @@ static VALUE pt_ps(int argc, VALUE* argv, VALUE klass){
48
51
  VALUE v_array = rb_ary_new();
49
52
  size_t length;
50
53
  char args[ARGS_MAX_LEN+1];
51
- /* Passed into sysctl call */
54
+
55
+ // Passed into sysctl call
52
56
  static const int name_mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0};
53
57
 
54
58
  rb_scan_args(argc, argv, "01", &v_pid);
55
59
 
56
- /* Get size of proc kproc buffer */
60
+ // Get size of proc kproc buffer
57
61
  err = sysctl( (int *) name_mib, PROC_MIB_LEN, NULL, &length, NULL, 0);
58
62
 
59
- /* TODO: Get error message from errno */
60
63
  if(err == -1)
61
64
  rb_raise(cProcTableError, strerror(errno));
62
65
 
63
- /* Populate the kproc buffer */
66
+ // Populate the kproc buffer
64
67
  procs = malloc(length);
65
68
 
66
- if(procs == NULL) rb_raise(cProcTableError, strerror(errno));
69
+ if(procs == NULL)
70
+ rb_raise(cProcTableError, strerror(errno));
67
71
 
68
72
  err = sysctl( (int *) name_mib, PROC_MIB_LEN, procs, &length, NULL, 0);
69
73
 
70
- /* TODO: Get error message from errno */
71
74
  if(err == -1)
72
75
  rb_raise(cProcTableError, strerror(errno));
73
76
 
74
- /* If we're here, we got our list */
77
+ // If we're here, we got our list
75
78
  count = length / sizeof(struct kinfo_proc);
76
79
 
77
- for(i=0; i<count; i++) {
78
-
79
- /* Reset some variables */
80
+ for(i = 0; i < count; i++) {
80
81
  v_tty_num = Qnil;
81
82
  v_tty_dev = Qnil;
82
83
  v_start_time = Qnil;
83
84
 
84
- /* If a PID is provided, skip unless the PID matches */
85
- if( (!NIL_P(v_pid)) && (procs[i].kp_proc.p_pid != NUM2INT(v_pid))) continue;
85
+ // If a PID is provided, skip unless the PID matches
86
+ if( (!NIL_P(v_pid)) && (procs[i].kp_proc.p_pid != NUM2INT(v_pid)) )
87
+ continue;
86
88
 
87
89
  *args = '\0';
88
90
 
@@ -102,13 +104,13 @@ static VALUE pt_ps(int argc, VALUE* argv, VALUE klass){
102
104
  fprintf(stderr, "err: %s LEN: %d\n", strerror(errno), args_size);
103
105
  }*/
104
106
 
105
- /* Get the start time of the process */
107
+ // Get the start time of the process
106
108
  v_start_time = rb_time_new(
107
109
  procs[i].kp_proc.p_un.__p_starttime.tv_sec,
108
110
  procs[i].kp_proc.p_un.__p_starttime.tv_usec
109
111
  );
110
112
 
111
- /* Get the state of the process */
113
+ // Get the state of the process
112
114
  switch(procs[i].kp_proc.p_stat)
113
115
  {
114
116
  case SIDL:
@@ -131,7 +133,7 @@ static VALUE pt_ps(int argc, VALUE* argv, VALUE klass){
131
133
  break;
132
134
  }
133
135
 
134
- /* Get ttynum and ttydev. If ttynum is -1, there is no tty */
136
+ // Get ttynum and ttydev. If ttynum is -1, there is no tty.
135
137
  if(procs[i].kp_eproc.e_tdev != -1){
136
138
  v_tty_num = INT2FIX(procs[i].kp_eproc.e_tdev),
137
139
  v_tty_dev = rb_str_new2(devname(procs[i].kp_eproc.e_tdev, S_IFCHR));
@@ -147,7 +149,7 @@ static VALUE pt_ps(int argc, VALUE* argv, VALUE klass){
147
149
  rb_str_new2(procs[i].kp_proc.p_comm),
148
150
  rb_str_new2(state),
149
151
  rb_float_new(procs[i].kp_proc.p_pctcpu),
150
- Qnil, //INT2FIX(procs[i].kp_proc.p_oncpu),
152
+ Qnil,
151
153
  v_tty_num,
152
154
  v_tty_dev,
153
155
  rb_str_new2(procs[i].kp_eproc.e_wmesg),
@@ -157,23 +159,22 @@ static VALUE pt_ps(int argc, VALUE* argv, VALUE klass){
157
159
  INT2FIX(procs[i].kp_proc.p_nice),
158
160
  rb_str_new2(args),
159
161
  v_start_time,
160
- /* For some processes, p_ru is NULL */
161
- procs[i].kp_proc.p_ru ? LONG2NUM(procs[i].kp_proc.p_ru->ru_maxrss) : Qnil,
162
- procs[i].kp_proc.p_ru ? LONG2NUM(procs[i].kp_proc.p_ru->ru_ixrss) : Qnil,
163
- procs[i].kp_proc.p_ru ? LONG2NUM(procs[i].kp_proc.p_ru->ru_idrss) : Qnil,
164
- procs[i].kp_proc.p_ru ? LONG2NUM(procs[i].kp_proc.p_ru->ru_isrss) : Qnil,
165
- procs[i].kp_proc.p_ru ? LONG2NUM(procs[i].kp_proc.p_ru->ru_minflt) : Qnil,
166
- procs[i].kp_proc.p_ru ? LONG2NUM(procs[i].kp_proc.p_ru->ru_majflt) : Qnil,
167
- procs[i].kp_proc.p_ru ? LONG2NUM(procs[i].kp_proc.p_ru->ru_nswap) : Qnil,
168
- procs[i].kp_proc.p_ru ? LONG2NUM(procs[i].kp_proc.p_ru->ru_inblock) : Qnil,
169
- procs[i].kp_proc.p_ru ? LONG2NUM(procs[i].kp_proc.p_ru->ru_oublock) : Qnil,
170
- procs[i].kp_proc.p_ru ? LONG2NUM(procs[i].kp_proc.p_ru->ru_msgsnd) : Qnil,
171
- procs[i].kp_proc.p_ru ? LONG2NUM(procs[i].kp_proc.p_ru->ru_msgrcv) : Qnil,
172
- procs[i].kp_proc.p_ru ? LONG2NUM(procs[i].kp_proc.p_ru->ru_nsignals) : Qnil,
173
- procs[i].kp_proc.p_ru ? LONG2NUM(procs[i].kp_proc.p_ru->ru_nvcsw) : Qnil,
174
- procs[i].kp_proc.p_ru ? LONG2NUM(procs[i].kp_proc.p_ru->ru_nivcsw) : Qnil,
175
- procs[i].kp_proc.p_ru ? LONG2NUM(procs[i].kp_proc.p_ru->ru_utime.tv_sec) : Qnil,
176
- procs[i].kp_proc.p_ru ? LONG2NUM(procs[i].kp_proc.p_ru->ru_stime.tv_sec) : Qnil
162
+ (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_maxrss) : Qnil,
163
+ (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_ixrss) : Qnil,
164
+ (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_idrss) : Qnil,
165
+ (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_isrss) : Qnil,
166
+ (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_minflt) : Qnil,
167
+ (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_majflt) : Qnil,
168
+ (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_nswap) : Qnil,
169
+ (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_inblock) : Qnil,
170
+ (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_oublock) : Qnil,
171
+ (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_msgsnd) : Qnil,
172
+ (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_msgrcv) : Qnil,
173
+ (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_nsignals) : Qnil,
174
+ (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_nvcsw) : Qnil,
175
+ (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_nivcsw) : Qnil,
176
+ (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_utime.tv_sec) : Qnil,
177
+ (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_stime.tv_sec) : Qnil
177
178
  );
178
179
 
179
180
  OBJ_FREEZE(v_pstruct); // This is read-only data
@@ -240,10 +241,10 @@ void Init_proctable(){
240
241
 
241
242
  /* Constants */
242
243
 
243
- /* 0.8.0: The version of this library */
244
+ /* 0.9.0: The version of the sys-proctable library */
244
245
  rb_define_const(cProcTable, "VERSION", rb_str_new2(SYS_PROCTABLE_VERSION));
245
246
 
246
- /* Structures */
247
+ /* Structs */
247
248
 
248
249
  sProcStruct = rb_struct_define("ProcTableStruct","pid","ppid","pgid","ruid",
249
250
  "rgid","comm","state","pctcpu","oncpu","tnum","tdev","wmesg",
data/lib/sys/top.rb CHANGED
@@ -18,9 +18,11 @@ module Sys
18
18
  #
19
19
  def self.top(num=10, field='pctcpu')
20
20
  field = field.to_s if field.is_a?(Symbol)
21
+
22
+ windows = /mswin|win32|dos|cygwin|mingw/i
21
23
 
22
24
  # Sort by pid on Windows by default
23
- if Config::CONFIG['host_os'].match('mswin') && field == 'pctcpu'
25
+ if Config::CONFIG['host_os'].match(windows) && field == 'pctcpu'
24
26
  field = 'pid'
25
27
  end
26
28
 
@@ -0,0 +1,40 @@
1
+ require 'rubygems'
2
+ require 'rbconfig'
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'sys-proctable'
6
+ gem.version = '0.8.2'
7
+ gem.author = 'Daniel J. Berger'
8
+ gem.license = 'Artistic 2.0'
9
+ gem.email = 'djberg96@gmail.com'
10
+ gem.homepage = 'http://www.rubyforge.org/projects/sysutils'
11
+ gem.platform = Gem::Platform::CURRENT
12
+ gem.summary = 'An interface for providing process table information'
13
+ gem.has_rdoc = true
14
+ gem.test_files = ['test/test_sys_proctable_all.rb']
15
+
16
+ # Additional files for your platform are added by the 'rake gem' task.
17
+ gem.files = [
18
+ 'benchmarks/bench_ps.rb',
19
+ 'examples/example_ps.rb',
20
+ 'lib/sys/top.rb',
21
+ 'CHANGES',
22
+ 'MANIFEST',
23
+ 'Rakefile',
24
+ 'README',
25
+ 'sys-proctable.gemspec'
26
+ ]
27
+
28
+ gem.rubyforge_project = 'sysutils'
29
+ gem.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST', 'doc/top.txt']
30
+
31
+ gem.add_development_dependency('test-unit', '>= 2.0.3')
32
+
33
+ gem.description = <<-EOF
34
+ The sys-proctable library provides an interface for gathering information
35
+ about processes on your system, i.e. the process table. Most major
36
+ platforms are supported and, while different platforms may return
37
+ different information, the external interface is identical across
38
+ platforms.
39
+ EOF
40
+ end
@@ -23,7 +23,7 @@ class TC_ProcTable_All < Test::Unit::TestCase
23
23
  end
24
24
 
25
25
  def test_version
26
- assert_equal('0.8.1', ProcTable::VERSION)
26
+ assert_equal('0.9.0', ProcTable::VERSION)
27
27
  end
28
28
 
29
29
  def test_fields
@@ -69,6 +69,11 @@ class TC_ProcTable_All < Test::Unit::TestCase
69
69
  def test_new_not_allowed
70
70
  assert_raise(NoMethodError){ Sys::ProcTable.new }
71
71
  end
72
+
73
+ def test_error_class_defined
74
+ assert_not_nil(Sys::ProcTable::Error)
75
+ assert_kind_of(StandardError, Sys::ProcTable::Error.new)
76
+ end
72
77
 
73
78
  def teardown
74
79
  @pid = nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sys-proctable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: x86-darwin-8
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -9,46 +9,46 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-08 00:00:00 -06:00
12
+ date: 2009-10-14 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: test-unit
17
- type: :runtime
17
+ type: :development
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 2.0.2
23
+ version: 2.0.3
24
24
  version:
25
- description: An interface for providing process table information
25
+ description: " The sys-proctable library provides an interface for gathering information\n about processes on your system, i.e. the process table. Most major\n platforms are supported and, while different platforms may return\n different information, the external interface is identical across\n platforms.\n"
26
26
  email: djberg96@gmail.com
27
27
  executables: []
28
28
 
29
29
  extensions:
30
- - ext/extconf.rb
30
+ - ext/darwin/extconf.rb
31
31
  extra_rdoc_files:
32
32
  - CHANGES
33
33
  - README
34
34
  - MANIFEST
35
35
  - doc/top.txt
36
- - ext/darwin/darwin.c
36
+ - ext/darwin/sys/proctable.c
37
37
  files:
38
+ - benchmarks/bench_ps.rb
39
+ - examples/example_ps.rb
38
40
  - lib/sys/top.rb
39
- - test/test_sys_proctable_all.rb
40
- - test/test_sys_proctable_darwin.rb
41
41
  - CHANGES
42
- - README
43
42
  - MANIFEST
43
+ - Rakefile
44
+ - README
45
+ - sys-proctable.gemspec
44
46
  - doc/top.txt
45
- - ext/darwin/darwin.c
46
- - ext/extconf.rb
47
- - ext/version.h
47
+ - ext/darwin/sys/proctable.c
48
48
  has_rdoc: true
49
49
  homepage: http://www.rubyforge.org/projects/sysutils
50
- licenses: []
51
-
50
+ licenses:
51
+ - Artistic 2.0
52
52
  post_install_message:
53
53
  rdoc_options: []
54
54
 
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  requirements: []
70
70
 
71
71
  rubyforge_project: sysutils
72
- rubygems_version: 1.3.1.2403
72
+ rubygems_version: 1.3.5
73
73
  signing_key:
74
74
  specification_version: 3
75
75
  summary: An interface for providing process table information
data/ext/extconf.rb DELETED
@@ -1,78 +0,0 @@
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')
data/ext/version.h DELETED
@@ -1,2 +0,0 @@
1
- /* version.h - stores the version number for all platforms (that use C) */
2
- #define SYS_PROCTABLE_VERSION "0.8.1"