Class: TorManager::ProcessHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/tormanager/process_helper.rb

Class Method Summary collapse

Class Method Details

.kill_process(pids) ⇒ Object



13
14
15
16
17
# File 'lib/tormanager/process_helper.rb', line 13

def kill_process pids
  to_array(pids).each do |pid|
    try_to_kill pid: pid, attempts: 5
  end
end

.port_is_open?(port) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
# File 'lib/tormanager/process_helper.rb', line 31

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

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
29
# File 'lib/tormanager/process_helper.rb', line 19

def process_pid_running? pid
  begin
    return false if pid.to_s == ''.freeze
    ipid = pid.to_i
    return false if ipid <= 0
    Process.kill(0, ipid)
    return true
  rescue
    return false
  end
end

.query_process(query) ⇒ Object



6
7
8
9
10
11
# File 'lib/tormanager/process_helper.rb', line 6

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