Class: KuberKit::Shell::Commands::SystemCommands
- Defined in:
- lib/kuber_kit/shell/commands/system_commands.rb
Instance Method Summary collapse
- #find_pids_by_name(shell, name) ⇒ Object
- #get_child_pids(shell, pid) ⇒ Object
- #kill_process(shell, pid) ⇒ Object
Instance Method Details
#find_pids_by_name(shell, name) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/kuber_kit/shell/commands/system_commands.rb', line 11 def find_pids_by_name(shell, name) shell .exec!("ps auxww | grep '#{name}' | grep -v 'grep' | awk '{print $2}'") .split("\n") .reject(&:empty?) .map(&:chomp) .map(&:to_i) rescue [] end |
#get_child_pids(shell, pid) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/kuber_kit/shell/commands/system_commands.rb', line 22 def get_child_pids(shell, pid) shell .exec!("pgrep -P #{pid}") .split("\n") .reject(&:empty?) .map(&:chomp) .map(&:to_i) rescue [] end |
#kill_process(shell, pid) ⇒ Object
2 3 4 5 6 7 8 9 |
# File 'lib/kuber_kit/shell/commands/system_commands.rb', line 2 def kill_process(shell, pid) # we need to use kill command directly sometimes, # because Process.kill doesn't kill processes created by system() call shell.exec!("kill -9 #{pid}", merge_stderr: true) true rescue false end |