pstree 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/Gemfile +5 -0
- data/README.rdoc +30 -0
- data/Rakefile +21 -0
- data/VERSION +1 -0
- data/bin/ruby-pstree +5 -0
- data/lib/pstree.rb +76 -0
- data/lib/pstree/version.rb +8 -0
- data/pstree.gemspec +36 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a6483f4b487ab4ec0b945edb4d9c58123b206ed5
|
4
|
+
data.tar.gz: e3ee7b02e2f7d05c678633dcf5dc255eb15406f7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2cf3d9536175720c6bbc0d7cca86bb63d93f436b452c181cff7705dcc4e346c379e54634cd6c6f8630ec70516b8425eae96d06bd6e0d5e33dc07dc71328e3800
|
7
|
+
data.tar.gz: bea7fa97a2481d8447e29f719fc3062f099e16f00d1b44b3c4fd3300b73c7ce5783bd87d1f893662661f3d3d59ff49da603f87c236b420c72552651b7848f191
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
= PSTree - Process Status Tree for UNIX in Ruby
|
2
|
+
|
3
|
+
== Description
|
4
|
+
|
5
|
+
This library can be used to create and display a process status tree as a Ruby
|
6
|
+
datastructure.
|
7
|
+
|
8
|
+
== Installation
|
9
|
+
|
10
|
+
Install the gem by typing
|
11
|
+
|
12
|
+
# gem install term-ansicolor
|
13
|
+
|
14
|
+
== Download
|
15
|
+
|
16
|
+
The homepage of this library is located at
|
17
|
+
|
18
|
+
You can display a simple process tree by executing the ruby-pstree script.
|
19
|
+
|
20
|
+
* http://flori.github.com/pstree
|
21
|
+
|
22
|
+
== Author
|
23
|
+
|
24
|
+
Florian Frank mailto:flori@ping.de
|
25
|
+
|
26
|
+
== License
|
27
|
+
|
28
|
+
This is free software; you can redistribute it and/or modify it under the
|
29
|
+
terms of the GNU General Public License Version 2 as published by the Free
|
30
|
+
Software Foundation: www.gnu.org/copyleft/gpl.html
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# vim: set filetype=ruby et sw=2 ts=2:
|
2
|
+
|
3
|
+
require 'gem_hadar'
|
4
|
+
|
5
|
+
GemHadar do
|
6
|
+
name 'pstree'
|
7
|
+
path_module 'PSTree'
|
8
|
+
module_type 'class'
|
9
|
+
author 'Florian Frank'
|
10
|
+
email 'flori@ping.de'
|
11
|
+
homepage "http://flori.github.com/#{name}"
|
12
|
+
summary 'Ruby library that builds a process tree of this host'
|
13
|
+
description 'This library uses the output of the ps command to creaste process tree data structure for the current host.'
|
14
|
+
licenses << 'GPL-2'
|
15
|
+
test_dir 'tests'
|
16
|
+
ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.rvmrc', 'coverage'
|
17
|
+
readme 'README.rdoc'
|
18
|
+
executables << 'ruby-pstree'
|
19
|
+
|
20
|
+
development_dependency 'simplecov'
|
21
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/bin/ruby-pstree
ADDED
data/lib/pstree.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'pstree/version'
|
2
|
+
|
3
|
+
class PSTree
|
4
|
+
class ProcStruct
|
5
|
+
def initialize(ppid, pid, user, cmd)
|
6
|
+
@ppid, @pid, @user, @cmd = ppid.to_i, pid.to_i, user, cmd
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :ppid, :pid, :user, :cmd
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
"%05u %s (%s)" % [ pid, cmd, user ]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
include Enumerable
|
17
|
+
|
18
|
+
def initialize(root_pid = nil)
|
19
|
+
@root_pid = root_pid.to_i
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
build
|
24
|
+
result = ''
|
25
|
+
recurse @root_pid,
|
26
|
+
-> children, last {
|
27
|
+
if children.zero?
|
28
|
+
result << (last ? '`-- ' : ' ')
|
29
|
+
else
|
30
|
+
result << (last ? '+-- ' : '| ')
|
31
|
+
end
|
32
|
+
} do |ps|
|
33
|
+
result << ps.to_s << "\n"
|
34
|
+
end
|
35
|
+
result
|
36
|
+
end
|
37
|
+
|
38
|
+
def each(&block)
|
39
|
+
build
|
40
|
+
recurse @root_pid, &block
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def build
|
47
|
+
@child_count = [ 0 ]
|
48
|
+
@process = {}
|
49
|
+
@pstree = Hash.new { |h,k| h[k] = [] }
|
50
|
+
pid = @root_pid.zero? ? nil : @root_pid
|
51
|
+
psoutput = `/bin/ps axww -o ppid,pid,user,command #{pid}`
|
52
|
+
psoutput.each_line do |line|
|
53
|
+
next if line !~ /^\s*\d+/
|
54
|
+
line.strip!
|
55
|
+
ps = ProcStruct.new *line.split(/\s+/, 4)
|
56
|
+
@process[ps.pid] = ps
|
57
|
+
@pstree[ps.ppid] << ps
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def recurse(pid, shift_callback = nil, level = 0, &node_callback)
|
62
|
+
@child_count[level] = @pstree[pid].size
|
63
|
+
for l in 0...level
|
64
|
+
shift_callback && shift_callback.call(@child_count[l], l == level - 1)
|
65
|
+
end
|
66
|
+
node_callback && (process = @process[pid]) && node_callback.call(process)
|
67
|
+
if @pstree.key?(pid)
|
68
|
+
@child_count[level] = @pstree[pid].size - 1
|
69
|
+
@pstree[pid].each do |ps|
|
70
|
+
recurse(ps.pid, shift_callback, level + 1 , &node_callback)
|
71
|
+
@child_count[level] -= 1
|
72
|
+
end
|
73
|
+
end
|
74
|
+
@pstree.delete pid
|
75
|
+
end
|
76
|
+
end
|
data/pstree.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "pstree"
|
5
|
+
s.version = "0.0.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Florian Frank"]
|
9
|
+
s.date = "2013-05-15"
|
10
|
+
s.description = "This library uses the output of the ps command to creaste process tree data structure for the current host."
|
11
|
+
s.email = "flori@ping.de"
|
12
|
+
s.executables = ["ruby-pstree"]
|
13
|
+
s.extra_rdoc_files = ["README.rdoc", "lib/pstree.rb", "lib/pstree/version.rb"]
|
14
|
+
s.files = [".gitignore", "Gemfile", "README.rdoc", "Rakefile", "VERSION", "bin/ruby-pstree", "lib/pstree.rb", "lib/pstree/version.rb", "pstree.gemspec"]
|
15
|
+
s.homepage = "http://flori.github.com/pstree"
|
16
|
+
s.licenses = ["GPL-2"]
|
17
|
+
s.rdoc_options = ["--title", "Pstree - Ruby library that builds a process tree of this host", "--main", "README.rdoc"]
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.rubygems_version = "2.0.3"
|
20
|
+
s.summary = "Ruby library that builds a process tree of this host"
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
s.specification_version = 4
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_development_dependency(%q<gem_hadar>, ["~> 0.3.1"])
|
27
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
28
|
+
else
|
29
|
+
s.add_dependency(%q<gem_hadar>, ["~> 0.3.1"])
|
30
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
31
|
+
end
|
32
|
+
else
|
33
|
+
s.add_dependency(%q<gem_hadar>, ["~> 0.3.1"])
|
34
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pstree
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Florian Frank
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: gem_hadar
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.3.1
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.3.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: simplecov
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: This library uses the output of the ps command to creaste process tree
|
42
|
+
data structure for the current host.
|
43
|
+
email: flori@ping.de
|
44
|
+
executables:
|
45
|
+
- ruby-pstree
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files:
|
48
|
+
- README.rdoc
|
49
|
+
- lib/pstree.rb
|
50
|
+
- lib/pstree/version.rb
|
51
|
+
files:
|
52
|
+
- .gitignore
|
53
|
+
- Gemfile
|
54
|
+
- README.rdoc
|
55
|
+
- Rakefile
|
56
|
+
- VERSION
|
57
|
+
- bin/ruby-pstree
|
58
|
+
- lib/pstree.rb
|
59
|
+
- lib/pstree/version.rb
|
60
|
+
- pstree.gemspec
|
61
|
+
homepage: http://flori.github.com/pstree
|
62
|
+
licenses:
|
63
|
+
- GPL-2
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options:
|
67
|
+
- --title
|
68
|
+
- Pstree - Ruby library that builds a process tree of this host
|
69
|
+
- --main
|
70
|
+
- README.rdoc
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.0.3
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Ruby library that builds a process tree of this host
|
89
|
+
test_files: []
|