Module: MoreCoreExtensions::ProcessPauseResume
- Defined in:
- lib/more_core_extensions/core_ext/process/pause_resume.rb
Instance Method Summary collapse
-
#alive?(pid) ⇒ Boolean
Returns whether or not the given process is running.
- #pause(pid) ⇒ Object
- #resume(pid) ⇒ Object
Instance Method Details
#alive?(pid) ⇒ Boolean
Returns whether or not the given process is running.
47 48 49 50 51 52 |
# File 'lib/more_core_extensions/core_ext/process/pause_resume.rb', line 47 def alive?(pid) Process.kill(0, pid) true rescue Errno::ESRCH false end |
#pause(pid) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/more_core_extensions/core_ext/process/pause_resume.rb', line 57 def pause(pid) return unless alive?(pid) begin handle = OpenProcess.call(PROCESS_SUSPEND_RESUME, 0, pid) if handle == 0 raise SystemCallError, Fiddle.win32_last_error, "OpenProcess" end if NtSuspendProcess.call(handle) != 0 raise SystemCallError, Fiddle.win32_last_error, "NtSuspendProcess" end ensure CloseHandle.call(handle) if handle end 1 # For cross-platform compatibility end |
#resume(pid) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/more_core_extensions/core_ext/process/pause_resume.rb', line 84 def resume(pid) return unless alive?(pid) begin handle = OpenProcess.call(PROCESS_SUSPEND_RESUME, 0, pid) if handle == 0 raise SystemCallError, Fiddle.win32_last_error, "OpenProcess" end if NtResumeProcess.call(handle) != 0 raise SystemCallError, Fiddle.win32_last_error, "NtResumeProcess" end ensure CloseHandle.call(handle) if handle end 1 # For cross-platform compatibility end |