Module: ExecSandbox::Wait4
- Defined in:
- lib/exec_sandbox/wait4.rb
Overview
Interface to the wait4 system call using the ffi library.
Defined Under Namespace
Class Method Summary collapse
-
.wait4(pid) ⇒ Hash
Waits for a process to end, and collects its exit status and resource usage.
Class Method Details
.wait4(pid) ⇒ Hash
Waits for a process to end, and collects its exit status and resource usage.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/exec_sandbox/wait4.rb', line 11 def self.wait4(pid) status_ptr = FFI::MemoryPointer.new :int rusage = ExecSandbox::Wait4::Rusage.new returned_pid = LibC.wait4(pid, status_ptr, 0, rusage.pointer) raise SystemCallError, FFI.errno if returned_pid < 0 status = { bits: status_ptr.read_int } status_ptr.free signal_code = status[:bits] & 0x7f status[:exit_code] = (signal_code != 0) ? -signal_code : status[:bits] >> 8 status[:user_time] = rusage[:ru_utime_sec] + rusage[:ru_utime_usec] * 0.000_001 status[:system_time] = rusage[:ru_stime_sec] + rusage[:ru_stime_usec] * 0.000_001 status[:rss] = rusage[:ru_maxrss] / 1024.0 return status end |