Class: TorManager::ProcessHelper
- Inherits:
-
Object
- Object
- TorManager::ProcessHelper
- Defined in:
- lib/tormanager/process_helper.rb
Class Method Summary collapse
- .kill_process(pids) ⇒ Object
- .port_is_open?(port) ⇒ Boolean
- .process_pid_running?(pid) ⇒ Boolean
- .query_process(query) ⇒ Object
Class Method Details
.kill_process(pids) ⇒ Object
15 16 17 18 19 |
# File 'lib/tormanager/process_helper.rb', line 15 def kill_process pids to_array(pids).each do |pid| try_to_kill pid: Integer(pid), attempts: 5 end end |
.port_is_open?(port) ⇒ Boolean
33 34 35 36 37 38 39 40 41 |
# File 'lib/tormanager/process_helper.rb', line 33 def port_is_open? port begin server = TCPServer.new('127.0.0.1', port) server.close return true rescue Errno::EADDRINUSE; return false end end |
.process_pid_running?(pid) ⇒ Boolean
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/tormanager/process_helper.rb', line 21 def process_pid_running? pid begin return false if pid.to_s == ''.freeze ipid = Integer(pid) return false if ipid <= 0 Process.kill(0, ipid) return true rescue return false end end |
.query_process(query) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/tormanager/process_helper.rb', line 8 def query_process query return [] unless query query_process_bash_cmd(query).split("\n").map{ |query_output_line| get_pid_from_query_process_output_line(query_output_line) }.compact end |