Class: VagrantPlugins::AVF::ProcessControl
- Inherits:
-
Object
- Object
- VagrantPlugins::AVF::ProcessControl
- Defined in:
- lib/vagrant_provider_avf/process_control.rb
Instance Method Summary collapse
- #alive?(process_id) ⇒ Boolean
- #spawn(command, out:, err:) ⇒ Object
- #stop(process_id, timeout:) ⇒ Object
Instance Method Details
#alive?(process_id) ⇒ Boolean
8 9 10 11 12 13 |
# File 'lib/vagrant_provider_avf/process_control.rb', line 8 def alive?(process_id) Process.kill(0, process_id) true rescue Errno::ESRCH false end |
#spawn(command, out:, err:) ⇒ Object
4 5 6 |
# File 'lib/vagrant_provider_avf/process_control.rb', line 4 def spawn(command, out:, err:) Process.spawn(*command, in: File::NULL, out: out, err: err, pgroup: true) end |
#stop(process_id, timeout:) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vagrant_provider_avf/process_control.rb', line 15 def stop(process_id, timeout:) return unless alive?(process_id) Process.kill("TERM", process_id) deadline = Time.now + timeout sleep(0.1) while alive?(process_id) && Time.now < deadline return reap(process_id) unless alive?(process_id) Process.kill("KILL", process_id) reap(process_id) end |