ps_f 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +1 -1
- data/bin/ps_f +26 -11
- metadata +3 -3
data/README
CHANGED
@@ -14,7 +14,7 @@ gem install ps_f
|
|
14
14
|
|
15
15
|
== Example
|
16
16
|
|
17
|
-
shell> ps_f
|
17
|
+
shell> ps_f axf
|
18
18
|
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
|
19
19
|
root 1 0.0 0.0 2512260 2160 ?? Ss 9:05AM 0:09.81 launchd
|
20
20
|
sugawara 260 0.0 0.1 2563928 13648 ?? Ss 9:05AM 0:01.49 \_ com.apple.dock.extra
|
data/bin/ps_f
CHANGED
@@ -1,13 +1,23 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
Version = '0.1.6'
|
4
|
-
|
2
|
+
ps_opts = (ARGV[0] || '').dup
|
5
3
|
wide = false
|
6
|
-
opt = OptionParser.new
|
7
|
-
opt.on('-w', '--wide') {|v| wide = v }
|
8
|
-
opt.parse!(ARGV)
|
9
4
|
|
10
|
-
|
5
|
+
if /\A-/ =~ ps_opts
|
6
|
+
system("ps #{ARGV.join(' ')}")
|
7
|
+
$stderr.puts('warning: BSD style only')
|
8
|
+
exit($?.success? ? 0 : 1)
|
9
|
+
end
|
10
|
+
|
11
|
+
unless ps_opts.empty? or /f/ =~ ps_opts
|
12
|
+
system("ps #{ARGV.join(' ')}")
|
13
|
+
exit($?.success? ? 0 : 1)
|
14
|
+
end
|
15
|
+
|
16
|
+
ps_opts.gsub!('f', '') if /f/ =~ ps_opts
|
17
|
+
ps_opts << 'u' if (ps_opts.empty? or /u/ !~ ps_opts)
|
18
|
+
wide = true if /w/ =~ ps_opts
|
19
|
+
|
20
|
+
out = `ps #{ps_opts} -o ppid,command`
|
11
21
|
exit 1 unless $?.success?
|
12
22
|
|
13
23
|
lines = out.to_a.map {|i| i.strip }
|
@@ -20,6 +30,7 @@ additional_headers = header_line.split(/\s+/).values_at(-2..-1)
|
|
20
30
|
|
21
31
|
rows = {}
|
22
32
|
tree = []
|
33
|
+
pid_list = []
|
23
34
|
|
24
35
|
lines.each do |line|
|
25
36
|
line_head = line[0, headers_border].strip.split(/\s+/, headers.length)
|
@@ -27,14 +38,18 @@ lines.each do |line|
|
|
27
38
|
|
28
39
|
line_head.each_with_index do |value, i|
|
29
40
|
rows[pid] ||= []
|
30
|
-
rows[pid] << value
|
41
|
+
rows[pid] << value unless ['COMMAND', 'CMD'].include?(headers[i])
|
31
42
|
end
|
32
43
|
|
33
|
-
|
44
|
+
tail_headers_border = headers_border
|
45
|
+
tail_headers_border -= 1 until ' ' == line[tail_headers_border - 1, 1]
|
46
|
+
|
47
|
+
ppid, command = line[tail_headers_border..-1].strip.split(/\s+/, additional_headers.length)
|
34
48
|
tree << [pid, ppid.to_i, command]
|
49
|
+
pid_list << pid
|
35
50
|
end
|
36
51
|
|
37
|
-
roots = tree.select {|pid, ppid, command|
|
52
|
+
roots = tree.select {|pid, ppid, command| not pid_list.include?(ppid) }
|
38
53
|
|
39
54
|
def asm(tree, roots, pre_prefix, cmd_list, basename_only)
|
40
55
|
h = {}
|
@@ -107,7 +122,7 @@ end
|
|
107
122
|
|
108
123
|
max_cols = 0
|
109
124
|
|
110
|
-
if $stdout.tty?
|
125
|
+
if not wide and $stdout.tty?
|
111
126
|
max_cols = `stty size cols 2> /dev/null`.strip.sub(/\A.*\s+/, '').first.to_i
|
112
127
|
end
|
113
128
|
|
metadata
CHANGED