Class: HawatelPS::Linux::ProcControl
- Inherits:
-
Object
- Object
- HawatelPS::Linux::ProcControl
- Defined in:
- lib/hawatel_ps/linux/proc_control.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#resume ⇒ String
Resume suspended process (equal to Kill -SIGCONT <pid> command).
-
#status ⇒ String
Check current process status.
-
#suspend ⇒ String
Suspend process without loss data (equal to Kill -SIGSTOP <pid> command).
-
#terminate ⇒ String
Kill process (equal to Kill -SIGKILL <pid> command).
Instance Method Details
#resume ⇒ String
Resume suspended process (equal to Kill -SIGCONT <pid> command)
46 47 48 49 50 51 52 53 54 |
# File 'lib/hawatel_ps/linux/proc_control.rb', line 46 def resume process_status = status if process_status == 'stopped' return status if Process.kill('CONT', @proc_attrs[:pid].to_i) end process_status rescue Errno::EPERM return 'non-privilaged operation' end |
#status ⇒ String
Check current process status
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/hawatel_ps/linux/proc_control.rb', line 11 def status sleep(0.2) status_file = "/proc/#{@proc_attrs[:pid]}/status" if File.readable?(status_file) File.foreach(status_file).each do |attr| return attr.split(' ')[2].chop[1..-1] if attr =~ /State:/ end end 'terminated' end |
#suspend ⇒ String
Suspend process without loss data (equal to Kill -SIGSTOP <pid> command)
29 30 31 32 33 34 35 36 37 |
# File 'lib/hawatel_ps/linux/proc_control.rb', line 29 def suspend process_status = status if process_status != 'terminated' && process_status != 'stopped' return status if Process.kill('STOP', @proc_attrs[:pid].to_i) end process_status rescue Errno::EPERM return 'non-privilaged operation' end |
#terminate ⇒ String
Kill process (equal to Kill -SIGKILL <pid> command)
63 64 65 66 67 68 69 70 71 |
# File 'lib/hawatel_ps/linux/proc_control.rb', line 63 def terminate process_status = status if process_status != 'terminated' return status if Process.kill('KILL', @proc_attrs[:pid]) end process_status rescue Errno::EPERM return 'non-privilaged operation' end |