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.
@@ -1,138 +0,0 @@
1
- /************************************************************************
2
- * linux.h
3
- *
4
- * Linux specific information, including struct layout.
5
- ************************************************************************/
6
- #include <dirent.h>
7
- #include <linux/limits.h>
8
- #include <unistd.h>
9
- #include <string.h>
10
- #include <ctype.h>
11
-
12
- #ifndef CLK_TCK
13
- #define CLK_TCK sysconf(_SC_CLK_TCK)
14
- #endif
15
-
16
- #define MAX_ENV_NAME 128
17
-
18
- /****************************************************************************
19
- * Note that the 20th field (between nice and itrealvalue) is not included
20
- * in our struct. It is a simple placeholder that was hardcoded for a
21
- * removed field. See the proc man page for more details.
22
- *
23
- * Also note that the environ attribute is not part of this struct, mostly
24
- * because I wouldn't know what type to set it to. It *is* part of the ruby
25
- * struct, however.
26
- ****************************************************************************/
27
- struct proc_info{
28
- char cmdline[ARG_MAX];
29
- char cwd[ARG_MAX];
30
- char exe[ARG_MAX];
31
- int pid;
32
- char name[ARG_MAX];
33
- int uid;
34
- int euid;
35
- int gid;
36
- int egid;
37
- char comm[ARG_MAX];
38
- char state[1];
39
- int ppid;
40
- int pgrp;
41
- int session;
42
- int tty_num;
43
- int tpgid;
44
- unsigned flags;
45
- unsigned minflt;
46
- unsigned cminflt;
47
- unsigned majflt;
48
- unsigned cmajflt;
49
- int utime;
50
- int stime;
51
- int cutime;
52
- int cstime;
53
- int priority;
54
- int nice;
55
- unsigned itrealvalue;
56
- int starttime;
57
- unsigned vsize;
58
- long rss;
59
- unsigned rlim;
60
- unsigned startcode;
61
- unsigned endcode;
62
- unsigned startstack;
63
- unsigned kstkesp;
64
- unsigned kstkeip;
65
- unsigned signal;
66
- unsigned blocked;
67
- unsigned sigignore;
68
- unsigned sigcatch;
69
- unsigned wchan;
70
- unsigned nswap;
71
- unsigned cnswap;
72
- int exit_signal;
73
- int processor;
74
- };
75
-
76
- /*****************************************************************************
77
- * This array's only purpose is for the 'fields()' class method. If there's
78
- * a way to report fields out of our defined struct (sProc), please tell me
79
- * how!
80
- *****************************************************************************/
81
- char *fields[] = {
82
- "cmdline",
83
- "cwd",
84
- "exe",
85
- "pid",
86
- "name",
87
- "uid",
88
- "euid",
89
- "gid",
90
- "egid",
91
- "comm",
92
- "state",
93
- "ppid",
94
- "pgrp",
95
- "session",
96
- "tty_num",
97
- "tpgid",
98
- "flags",
99
- "minflt",
100
- "cminflt",
101
- "majflt",
102
- "cmajflt",
103
- "utime",
104
- "stime",
105
- "cutime",
106
- "cstime",
107
- "priority",
108
- "nice",
109
- "itrealvalue",
110
- "starttime",
111
- "vsize",
112
- "rss",
113
- "rlim",
114
- "startcode",
115
- "endcode",
116
- "startstack",
117
- "kstkesp",
118
- "kstkeip",
119
- "signal",
120
- "blocked",
121
- "sigignore",
122
- "sigcatch",
123
- "wchan",
124
- "nswap",
125
- "cnswap",
126
- "exit_signal",
127
- "processor",
128
- "environ"
129
- };
130
-
131
- /* Helper function to remove trailing whitespace. Use for cmdline info */
132
- void trimr(char* s){
133
- char* p = s + strlen(s);
134
- while(--p >= s && isspace(*p))
135
- ;
136
-
137
- *++p = 0;
138
- }
@@ -1,70 +0,0 @@
1
- ########################################################
2
- # test.rb
3
- #
4
- # Generic test script for folks without TestUnit, or
5
- # for general futzing.
6
- ########################################################
7
- if File.basename(Dir.pwd) == "test"
8
- require "ftools"
9
- Dir.chdir ".."
10
- $:.unshift Dir.pwd
11
-
12
- begin
13
- Dir.mkdir("sys") unless File.exists?("sys")
14
- rescue Exception => e
15
- STDERR.puts "Problem creating 'sys' directory. Exiting..."
16
- exit
17
- end
18
-
19
- extension = ".so"
20
- extension = ".sl" if RUBY_PLATFORM =~ /hpux/i
21
- extension = ".bundle" if RUBY_PLATFORM =~ /powerpc|darwin|mac/i
22
-
23
- object_file = "proctable" + extension
24
-
25
- # Alter as desired
26
- if File::ALT_SEPARATOR
27
- pure = "lib/os/windows.rb" # Comment this out to use C extension
28
- #pure = object_file # Uncomment this to use C extension
29
- begin
30
- File.copy(pure,"sys/proctable.rb") # Comment out to use C
31
- #File.copy(pure,"sys") # Uncomment to use C
32
- rescue Exception => e
33
- puts "Problem copying #{pure} file: #{e}"
34
- exit
35
- end
36
- else
37
- begin
38
- File.copy(object_file,'sys/')
39
- rescue Exception => e
40
- puts "Problem copying #{object_file} file: #{e}"
41
- exit
42
- end
43
- end
44
-
45
- end
46
-
47
- require "sys/proctable"
48
- include Sys
49
-
50
- puts 'VERSION: ' + ProcTable::VERSION
51
- puts 'Fields: ' + ProcTable.fields.join("\n")
52
-
53
- puts "-" * 30
54
- sleep 1
55
-
56
- ProcTable.ps{ |s|
57
- ProcTable.fields{ |f|
58
- if f == "environ"
59
- puts "#{f}:"
60
- s.send(f).each{ |k,v|
61
- puts "\t#{k} => #{v}"
62
- }
63
- else
64
- puts "#{f}: [" + s.send(f).to_s + "]"
65
- end
66
- }
67
- puts '=' * 30
68
- }
69
-
70
- puts "Finished"