Class: Lsof
- Inherits:
-
Object
- Object
- Lsof
- Defined in:
- lib/lsof.rb
Class Method Summary collapse
- .find_pids_cmd(port) ⇒ Object
- .kill(port) ⇒ Object
- .listener_pids(port) ⇒ Object
- .running?(port) ⇒ Boolean
-
.running_remotely?(server, port) ⇒ Boolean
this isn’t really lsof, but it’s solving the same problem.
Class Method Details
.find_pids_cmd(port) ⇒ Object
25 26 27 |
# File 'lib/lsof.rb', line 25 def find_pids_cmd(port) "lsof -i tcp:#{port} | grep '(LISTEN)' | awk '{print $2}'" end |
.kill(port) ⇒ Object
3 4 5 6 |
# File 'lib/lsof.rb', line 3 def kill(port) pid = listener_pids(port) `#{find_pids_cmd(port)} | xargs kill 2>&1` end |
.listener_pids(port) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/lsof.rb', line 18 def listener_pids(port) output = `#{find_pids_cmd(port)}` output.split("\n").map do |port| Integer(port) end end |
.running?(port) ⇒ Boolean
8 9 10 |
# File 'lib/lsof.rb', line 8 def running?(port) listener_pids(port).empty? ? false : true end |
.running_remotely?(server, port) ⇒ Boolean
this isn’t really lsof, but it’s solving the same problem
13 14 15 16 |
# File 'lib/lsof.rb', line 13 def running_remotely?(server, port) TCPSocket.new(server, port).close rescue return false return true end |