sys-proctable 0.7.3 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +7 -3
- data/MANIFEST +41 -0
- data/README +119 -56
- data/doc/freebsd.txt +43 -54
- data/doc/hpux.txt +40 -52
- data/doc/linux.txt +36 -51
- data/doc/solaris.txt +50 -70
- data/doc/top.txt +44 -45
- data/doc/windows.txt +60 -60
- data/ext/extconf.rb +101 -0
- data/ext/sunos/sunos.c +374 -0
- data/ext/sunos/sunos.h +177 -0
- data/{lib → ext}/version.h +1 -1
- data/lib/sys/top.rb +23 -0
- data/test/tc_all.rb +17 -21
- data/test/tc_freebsd.rb +9 -5
- data/test/tc_hpux.rb +10 -7
- data/test/tc_kvm_bsd.rb +10 -5
- data/test/tc_linux.rb +9 -6
- data/test/tc_sunos.rb +9 -5
- data/test/tc_top.rb +14 -15
- data/test/tc_windows.rb +7 -9
- data/test/test_memleak.rb +2 -2
- metadata +23 -18
- data/extconf.rb +0 -104
- data/lib/os/linux.c +0 -315
- data/lib/os/linux.h +0 -138
- data/test/test.rb +0 -70
data/doc/linux.txt
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
|
1
|
+
= Description
|
2
2
|
sys-proctable
|
3
3
|
|
4
4
|
A Ruby version of the 'ps' command. This is a C extension, not parsed
|
5
5
|
output. For Linux, process information is read out of /proc.
|
6
6
|
|
7
|
-
|
7
|
+
= Synopsis
|
8
8
|
require 'sys/proctable'
|
9
9
|
include Sys
|
10
10
|
|
@@ -32,70 +32,55 @@
|
|
32
32
|
...
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
= Constants
|
36
36
|
VERSION
|
37
|
-
|
37
|
+
Returns the current version number for this package (as a string).
|
38
38
|
|
39
|
-
|
39
|
+
= Class Methods
|
40
40
|
ProcTable.fields
|
41
|
-
|
42
|
-
|
41
|
+
Returns a list of fields available on the current OS. May also take a
|
42
|
+
block.
|
43
43
|
|
44
44
|
ProcTable.ps(pid=nil)
|
45
45
|
ProcTable.ps{ |s| ... }
|
46
|
-
|
47
|
-
|
48
|
-
|
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
49
|
|
50
|
-
|
51
|
-
|
50
|
+
If a process id is provided, a single ProcTable struct is returned, or
|
51
|
+
nil if the pid is not found.
|
52
52
|
|
53
|
-
|
53
|
+
= Exception Classes
|
54
54
|
ProcTableError < StandardError
|
55
|
-
|
55
|
+
Raised if the /proc field is unreadable and/or unmounted.
|
56
56
|
|
57
|
-
|
58
|
-
|
57
|
+
= Supported fields
|
58
|
+
You can view the supported fields with the "fields()" class method.
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
= Future Plans
|
61
|
+
Create a pure Ruby version as an alternative.
|
62
|
+
Change the ttynum field to ttydev and return a string instead of an int.
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
= Known Bugs
|
65
|
+
None known. Please log any bugs on the project page at
|
66
|
+
http://www.rubyforge.org/projects/sysutils
|
67
67
|
|
68
|
-
|
69
|
-
|
68
|
+
= License
|
69
|
+
Ruby's
|
70
70
|
|
71
|
-
|
72
|
-
|
71
|
+
= Copyright
|
72
|
+
(C) 2003-2006 Daniel J. Berger
|
73
73
|
All Rights Reserved
|
74
74
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
== Credits
|
86
|
-
This module is largely based on the Perl module Proc::ProcessTable by
|
87
|
-
Dan Urist. Many ideas, as well as large chunks of code, were taken
|
88
|
-
from his work. So, a big THANK YOU goes out to Dan Urist.
|
89
|
-
|
90
|
-
A big thanks also goes out to Mike Hall who was very helpful with ideas,
|
91
|
-
logic and testing.
|
92
|
-
|
93
|
-
Thanks also go to Sean Chittenden for providing an account on one of his
|
94
|
-
FreeBSD machines. This is how the FreeBSD support was (initially) added.
|
95
|
-
|
96
|
-
Thanks go to James Hranicky for providing a patch that grabs name, eid,
|
97
|
-
euid, gid and guid info in the Linux version, along with some general
|
98
|
-
debugging help.
|
75
|
+
= Warranty
|
76
|
+
This package is provided "as is" and without any express or
|
77
|
+
implied warranties, including, without limitation, the implied
|
78
|
+
warranties of merchantability and fitness for a particular purpose.
|
79
|
+
|
80
|
+
= Author
|
81
|
+
Daniel J. Berger
|
82
|
+
djberg96 at nospam at gmail dot com
|
83
|
+
rubyhacker1 on IRC (Freenode)
|
99
84
|
|
100
|
-
|
85
|
+
= See Also
|
101
86
|
ps, proc(5)
|
data/doc/solaris.txt
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
|
1
|
+
= Description
|
2
2
|
sys-proctable
|
3
3
|
|
4
4
|
A Ruby version of the 'ps' command. This is a C extension, not parsed
|
5
5
|
output. For Solaris, data is read out of /proc via the psinfo struct.
|
6
6
|
|
7
|
-
|
7
|
+
= Synopsis
|
8
8
|
require 'sys/proctable'
|
9
9
|
include Sys
|
10
10
|
|
@@ -30,91 +30,71 @@
|
|
30
30
|
...
|
31
31
|
end
|
32
32
|
|
33
|
-
|
33
|
+
= Constants
|
34
34
|
VERSION
|
35
|
-
|
35
|
+
Returns the current version number for this package (as a string).
|
36
36
|
|
37
|
-
|
37
|
+
= Class Methods
|
38
38
|
ProcTable.fields
|
39
|
-
|
40
|
-
|
39
|
+
Returns a list of fields available on the current OS. May also take
|
40
|
+
a block.
|
41
41
|
|
42
42
|
ProcTable.ps(pid=nil)
|
43
43
|
ProcTable.ps{ |s| ... }
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
If no pid is included as an argument, in block form it
|
45
|
+
returns a struct of type ProcTableStruct for every process in the proc
|
46
|
+
table. Otherwise it returns an array of ProcTable struct's. If a pid
|
47
|
+
is provided it will return a single ProcTable struct for that pid, or
|
48
|
+
nil if it is not found.
|
49
49
|
|
50
|
-
|
50
|
+
= Exception Classes
|
51
51
|
ProcTableError < StandardError
|
52
|
-
|
52
|
+
Raised if the /proc directory is unreadable and/or unmounted.
|
53
53
|
|
54
|
-
|
55
|
-
|
54
|
+
= Supported fields
|
55
|
+
You can view the supported fields with the "fields()" class method.
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
= Future Plans
|
58
|
+
Return a more meaningful result for the wchan member (2.6+).
|
59
|
+
Add env info where possible.
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
= Notes
|
62
|
+
The "comm" field isn't really part of the psinfo struct. It is just a copy
|
63
|
+
(i.e. is identical to) the "fname" field. I added it to provide a degree
|
64
|
+
of consistency between all of the platforms. I will also make a point
|
65
|
+
of adding it to any future platform releases.
|
66
66
|
|
67
|
-
|
68
|
-
|
67
|
+
The cmdline string is limited to 80 characters, except for those processes
|
68
|
+
which you (or your program) own.
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
The ttydev field is, for now, an integer. If there is no associated tty with
|
71
|
+
the process, a -1 is returned. In the future, this field will be changed to
|
72
|
+
a string (i.e. the actual device name).
|
73
73
|
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
I suppose I *could* add a -lkvm version for Solaris (this is what Dan Urist
|
75
|
+
is now using in Proc::ProcessTable) but I haven't found a compelling reason
|
76
|
+
to do so. If you think you have one, please let me know.
|
77
77
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
rebuild Ruby with the --disable-largefile option or you can build a 64 bit
|
82
|
-
Ruby.
|
83
|
-
|
84
|
-
I have posted this issue to the mailing list, but have not received a
|
85
|
-
satisfactory response. I suspect there is an issue with the configure
|
86
|
-
script, because this does not happen with Ruby 1.6.x.
|
87
|
-
|
88
|
-
Please log any additional bugs on the SourceForge project page at
|
89
|
-
http://www.rubyforge.org/projects/sysutils
|
78
|
+
= Known Bugs
|
79
|
+
None that I am aware of. Please log any bugs on the RubyForge project page at
|
80
|
+
http://www.rubyforge.org/projects/sysutils
|
90
81
|
|
91
|
-
|
92
|
-
|
82
|
+
= License
|
83
|
+
Ruby's
|
93
84
|
|
94
|
-
|
95
|
-
|
96
|
-
|
85
|
+
= Copyright
|
86
|
+
(C) 2003-2006 Daniel J. Berger
|
87
|
+
All Rights Reserved.
|
97
88
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
89
|
+
= Warranty
|
90
|
+
This package is provided "as is" and without any express or
|
91
|
+
implied warranties, including, without limitation, the implied
|
92
|
+
warranties of merchantability and fitness for a particular purpose.
|
102
93
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
== Credits
|
109
|
-
This module is largely based on the Perl module Proc::ProcessTable by
|
110
|
-
Dan Urist. Many ideas, as well as large chunks of code, were taken
|
111
|
-
from his work. So, a big THANK YOU goes out to Dan Urist.
|
112
|
-
|
113
|
-
A big thanks also goes out to Mike Hall who was very helpful with ideas,
|
114
|
-
logic and testing.
|
115
|
-
|
116
|
-
Thanks also go to Sean Chittenden for providing an account on one of his
|
117
|
-
FreeBSD machines. This is how the FreeBSD support was (initially) added.
|
94
|
+
= Author
|
95
|
+
Daniel J. Berger
|
96
|
+
djberg96 at nospam at gmail dot com
|
97
|
+
imperator on IRC (Freenode)
|
118
98
|
|
119
|
-
|
120
|
-
|
99
|
+
= See Also
|
100
|
+
ps, proc
|
data/doc/top.txt
CHANGED
@@ -1,54 +1,53 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
15
|
|
16
|
-
|
16
|
+
= Constants
|
17
17
|
VERSION
|
18
|
-
|
18
|
+
Returns the version number of this package as a String.
|
19
19
|
|
20
|
-
|
20
|
+
= Class Methods
|
21
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.
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
Not all fields are available on all platforms. Please check your
|
30
|
-
platform specific documentation for which fields are available.
|
31
|
-
|
32
|
-
I used sort() instead of sort_by() internally to maintain backward
|
33
|
-
compatability with Ruby 1.6.8, which I happen to need.
|
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
|
+
I used sort() instead of sort_by() internally to maintain backward
|
32
|
+
compatability with Ruby 1.6.8, which I happen to need.
|
34
33
|
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
= Bugs
|
35
|
+
None that I'm aware of. Please log bug reports on the project page at
|
36
|
+
http://www.rubyforge.org/projects/sysutils
|
38
37
|
|
39
|
-
|
40
|
-
|
38
|
+
= License
|
39
|
+
Ruby's
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
= Copyright
|
42
|
+
(C) 2004-2006 Daniel J. Berger
|
43
|
+
All Rights Reserved.
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
45
|
+
= Warranty
|
46
|
+
This package is provided "as is" and without any express or
|
47
|
+
implied warranties, including, without limitation, the implied
|
48
|
+
warranties of merchantability and fitness for a particular purpose.
|
49
|
+
|
50
|
+
= Author
|
51
|
+
Daniel J. Berger
|
52
|
+
djberg96 at nospam at gmail dot com
|
53
|
+
imperator on IRC (Freenode)
|
data/doc/windows.txt
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
|
1
|
+
= Description
|
2
2
|
A Ruby interface for gathering process information. For MS Windows,
|
3
3
|
the process information is gathered via OLE + WMI, using pure Ruby.
|
4
4
|
|
5
|
-
|
5
|
+
= Synopsis
|
6
6
|
require 'sys/proctable'
|
7
7
|
include Sys
|
8
8
|
|
@@ -30,32 +30,32 @@
|
|
30
30
|
...
|
31
31
|
end
|
32
32
|
|
33
|
-
|
33
|
+
= Constants
|
34
34
|
VERSION
|
35
|
-
|
35
|
+
Returns the current version number for this package (as a string).
|
36
36
|
|
37
|
-
|
37
|
+
= Class Methods
|
38
38
|
ProcTable.fields
|
39
|
-
|
40
|
-
|
39
|
+
Returns an Array of fields available on the current OS in the
|
40
|
+
ProcTableStruct.
|
41
41
|
|
42
42
|
ProcTable.ps(pid=nil, host='localhost')
|
43
43
|
ProcTable.ps{ |s| ... }
|
44
|
-
|
45
|
-
|
44
|
+
Returns a struct of type ProcTableStruct for every process in the proc
|
45
|
+
table in block form. Otherwise it returns an array of ProcTableStruct's.
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
47
|
+
If 'pid' is provided, then only a struct for that pid is returned, or
|
48
|
+
nil if it is not found.
|
49
|
+
|
50
|
+
If 'host' is provided, then processes from that host are gathered. By
|
51
|
+
default, process information is gathered on the local host.
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
= Supported fields
|
54
|
+
The currently supported fields for MS Windows (i.e. your ProcTable struct
|
55
|
+
members) are:
|
56
56
|
|
57
|
-
|
58
|
-
|
57
|
+
caption, cmdline, comm, creation_class_name, creation_date,
|
58
|
+
cs_creation_class_name, cs_name, description, executable_path,
|
59
59
|
execution_state, handle, handle_count, install_date, kernel_mode_time,
|
60
60
|
maximum_working_set_size, minimum_working_set_size, name,
|
61
61
|
os_creation_class_name, os_name, other_operation_count,
|
@@ -70,53 +70,53 @@ ProcTable.ps{ |s| ... }
|
|
70
70
|
|
71
71
|
You can also view them with the fields() class method.
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
73
|
+
= Notes
|
74
|
+
For the sake of attempting to provide a somewhat common API, the 'comm'
|
75
|
+
and 'cmdline' fields have been included as part of the structure. The
|
76
|
+
'comm' member corresponds to the Name attribute of Win32_Process. The
|
77
|
+
'cmdline' attribute corresponds to either the Executable_Path attribute
|
78
|
+
(on Windows 2000 or earlier) or the CommandLine attribute (on Windows XP
|
79
|
+
and later).
|
80
80
|
|
81
|
-
|
82
|
-
|
83
|
-
|
81
|
+
Also note that the ProcessId and ParentProcessId attributes have been
|
82
|
+
abbreviated as 'pid' and 'ppid' in the struct members, again to keep the
|
83
|
+
members more consistent between platforms.
|
84
84
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
85
|
+
The "Mem Usage" and "VM Size" that you may be used to seeing in your Task
|
86
|
+
Manager window (probably) correspond to the 'working_set_size' and
|
87
|
+
'page_file_usage' struct members, respectively, keeping in mind that
|
88
|
+
those values are in bytes, not kilobytes. I say 'probably' because
|
89
|
+
comments that I've read online indicate that it may not always line up
|
90
|
+
with what you see in the Task Manager, based on the current version (or
|
91
|
+
even Service Pack) of Windows that you are using.
|
92
92
|
|
93
|
-
|
94
|
-
|
95
|
-
|
93
|
+
= Future Plans
|
94
|
+
Possibly use the Win32_PerfFormattedData_PerfProc_Process class to get
|
95
|
+
additional process information.
|
96
96
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
97
|
+
= Known Bugs
|
98
|
+
Versions of Ruby earlier than 1.8.2 resulted in segfaults when trying to
|
99
|
+
run this code. You will likely encounter the same behavior.
|
100
|
+
|
101
|
+
Please log any additional bug reports on the project page at
|
102
|
+
http://www.rubyforge.org/projects/sysutils
|
103
103
|
|
104
|
-
|
105
|
-
|
104
|
+
= License
|
105
|
+
Ruby's
|
106
106
|
|
107
|
-
|
108
|
-
|
109
|
-
|
107
|
+
= Copyright
|
108
|
+
(C) 2003-2006 Daniel J. Berger
|
109
|
+
All Rights Reserved
|
110
110
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
111
|
+
= Warranty
|
112
|
+
This package is provided "as is" and without any express or
|
113
|
+
implied warranties, including, without limitation, the implied
|
114
|
+
warranties of merchantability and fitness for a particular purpose.
|
115
115
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
116
|
+
= Author
|
117
|
+
Daniel J. Berger
|
118
|
+
djberg96 at nospam at gmail dot com
|
119
|
+
imperator on IRC (freenode)
|
120
120
|
|
121
|
-
|
122
|
-
|
121
|
+
= See Also
|
122
|
+
OLE + WMI
|