Module: ExecSandbox::Wait4
- Defined in:
- lib/exec_sandbox/wait4.rb
Overview
Interface to the wait4 system call using the ffi library.
Defined Under Namespace
Constant Summary collapse
- WNOHANG =
Option passed to LibC::wait4.
1
Class Method Summary collapse
- ._wait4(pid, options) ⇒ Object
-
.wait4(pid) ⇒ Hash
Waits for a process to end, and collects its exit status and resource usage.
-
.wait4_nonblock(pid) ⇒ Hash
Collects a child process’ exit status and resource usage.
Class Method Details
._wait4(pid, options) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/exec_sandbox/wait4.rb', line 27 def _wait4(pid, ) status_ptr = FFI::MemoryPointer.new :int rusage = ExecSandbox::Wait4::Rusage.new returned_pid = LibC.wait4(pid, status_ptr, , rusage.pointer) raise SystemCallError, FFI.errno if returned_pid < 0 return nil 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 |
.wait4(pid) ⇒ Hash
Waits for a process to end, and collects its exit status and resource usage.
11 12 13 |
# File 'lib/exec_sandbox/wait4.rb', line 11 def self.wait4(pid) _wait4 pid, 0 end |
.wait4_nonblock(pid) ⇒ Hash
Collects a child process’ exit status and resource usage.
21 22 23 |
# File 'lib/exec_sandbox/wait4.rb', line 21 def self.wait4_nonblock(pid) _wait4 pid, WNOHANG end |