rlps 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -5
- data/lib/rlps.rb +6 -0
- data/lib/rlps/helper/parser.rb +1 -1
- data/lib/rlps/process.rb +10 -16
- data/lib/rlps/version.rb +1 -1
- data/rlps.gemspec +1 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c583ee6da08cac5398774eb33ca3c78a59a0032
|
4
|
+
data.tar.gz: ea80e6d8687aa5df423c8a691f283f5f55ebcf5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9f326a876581da1ec41faf51686c7385ca5b37dac0c28520139cc8ef653efc2bfe2804f719ac8357ba69ca4b9cd16836e70925cc7260aab6a3bd0c6e2a448b5
|
7
|
+
data.tar.gz: 1824536a28103ae1115f5c209933e716d9b163cc76ec8c8086f7cc12220d6abe2c7b9d59b5fdc2a3718b7e8f926b4756473e0485a63a4f73c58948ee24331083
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# RLPS
|
2
2
|
|
3
|
-
**RLPS** is a very simple and pure Ruby gem which sole
|
3
|
+
**RLPS** is a very simple and pure Ruby gem which sole purpose is to get a **list** of the currently **running processes** in a **Linux** system by reading data from Linux /proc/ directory.
|
4
4
|
More information read The Linux Documentation Project [topic](http://tldp.org/LDP/Linux-Filesystem-Hierarchy/html/proc.html) on this subject.
|
5
5
|
## Installation
|
6
6
|
|
@@ -32,9 +32,9 @@ p my_processes[0].pid # => 1
|
|
32
32
|
```
|
33
33
|
Returns a list of [RLPS::Process](http://www.github.com/nemoload) objects.
|
34
34
|
## CLI
|
35
|
-
**TL;DR: Don't.**
|
36
|
-
Although this gem wasn't made to be used as a CLI application, it can act as a very bad,
|
37
|
-
|
35
|
+
**TL;DR: Don't.**
|
36
|
+
Although this gem wasn't made to be used as a CLI application, it can act as a very bad, inefficient version of Linux ``` $ ps -e ```:
|
37
|
+
|
38
38
|
$ rlps
|
39
39
|
|
40
40
|
## Contributing
|
@@ -45,4 +45,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/nemolo
|
|
45
45
|
## License
|
46
46
|
|
47
47
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
48
|
-
|
data/lib/rlps.rb
CHANGED
@@ -15,6 +15,12 @@ module RLPS
|
|
15
15
|
@processes ||= parse_processes
|
16
16
|
end
|
17
17
|
|
18
|
+
# Return this process RLPS::Process object.
|
19
|
+
def this_process
|
20
|
+
process = RLPS.processes.select { |p| p.pid == ::Process.pid }
|
21
|
+
RLPS::Process.new name: process[0].name, pid: ::Process.pid
|
22
|
+
end
|
23
|
+
|
18
24
|
# Update the already fetched processes list.
|
19
25
|
def update!
|
20
26
|
@process = parse_processes
|
data/lib/rlps/helper/parser.rb
CHANGED
@@ -2,7 +2,6 @@ require 'rlps/string'
|
|
2
2
|
require 'rlps/process'
|
3
3
|
|
4
4
|
module RLPS
|
5
|
-
|
6
5
|
# This class parses Linux's /proc/ directory status file.
|
7
6
|
class Parser
|
8
7
|
# This method gets a /proc/ directory, then it parses
|
@@ -17,6 +16,7 @@ module RLPS
|
|
17
16
|
end
|
18
17
|
end
|
19
18
|
RLPS::Process.new name: status['Name'], pid: status['Pid'].to_i
|
19
|
+
# TODO: add more information
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
data/lib/rlps/process.rb
CHANGED
@@ -4,10 +4,10 @@ module RLPS
|
|
4
4
|
##
|
5
5
|
class Process
|
6
6
|
attr_reader :name, :pid
|
7
|
+
|
7
8
|
# Takes two arguments _:name_ and _:pid_
|
8
9
|
# If called without any arguments it calls RLPS::Process.this_process.
|
9
|
-
|
10
|
-
# RLPS::Process.new name: "ruby", pid: 2365
|
10
|
+
|
11
11
|
def initialize(**args)
|
12
12
|
#-- other = args.select { |k, _v| ((k == :name) &&
|
13
13
|
# !args[k].nil?) || ((k == :pid) && !args[k].nil?) }
|
@@ -21,16 +21,17 @@ module RLPS
|
|
21
21
|
"#{@name}: #{@pid}"
|
22
22
|
end
|
23
23
|
|
24
|
+
def ==(obj)
|
25
|
+
obj.pid == @pid && obj.name.casecmp(@name).zero?
|
26
|
+
end
|
27
|
+
|
24
28
|
def to_i
|
25
29
|
@pid
|
26
30
|
end
|
27
31
|
|
28
|
-
# Returns true if the process is
|
29
|
-
def
|
30
|
-
!RLPS.processes.select
|
31
|
-
p.pid == @pid &&
|
32
|
-
p.name.casecmp(@name.downcase).zero?
|
33
|
-
end.empty?
|
32
|
+
# Returns true if the process is running.
|
33
|
+
def is_running?
|
34
|
+
!RLPS.processes.select { |p| p == self }.empty?
|
34
35
|
end
|
35
36
|
|
36
37
|
# Send INT signal to the process as a default behaviour.
|
@@ -40,15 +41,8 @@ module RLPS
|
|
40
41
|
::Process.kill(signal, @pid)
|
41
42
|
end
|
42
43
|
|
43
|
-
# Return this process RLPS::Process object.
|
44
|
-
def self.this_process
|
45
|
-
process = RLPS.processes.select { |p| p.pid == ::Process.pid }
|
46
|
-
RLPS::Process.new name: process[0].name, pid: ::Process.pid
|
47
|
-
end
|
48
44
|
|
49
|
-
|
50
|
-
# TODO
|
51
|
-
end
|
45
|
+
|
52
46
|
alias inspect to_s
|
53
47
|
end
|
54
48
|
end
|
data/lib/rlps/version.rb
CHANGED
data/rlps.gemspec
CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.homepage = 'https://nemoload.github.io'
|
17
17
|
spec.license = 'MIT'
|
18
18
|
|
19
|
+
spec.required_ruby_version = '~> 2.0'
|
19
20
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
20
21
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
21
22
|
# if spec.respond_to?(:metadata)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rlps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ahmed Khaled
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -101,9 +101,9 @@ require_paths:
|
|
101
101
|
- lib
|
102
102
|
required_ruby_version: !ruby/object:Gem::Requirement
|
103
103
|
requirements:
|
104
|
-
- - "
|
104
|
+
- - "~>"
|
105
105
|
- !ruby/object:Gem::Version
|
106
|
-
version: '0'
|
106
|
+
version: '2.0'
|
107
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
109
|
- - ">="
|