Module: OS::Mac::FFI::LibProc Private
- Extended by:
- NativeLibrary
- Defined in:
- os/mac/ffi/libproc.rb
Overview
This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.
libproc wrapper
Constant Summary collapse
- PROC_PIDT_SHORTBSDINFO =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
sys/proc_info.h:
#define PROC_PIDT_SHORTBSDINFO 13 13
Class Method Summary collapse
-
.parent_pid(pid) ⇒ Integer?
private
libproc.h: int proc_pidinfo(int pid, int flavor, uint64_t arg, void *buffer, int buffersize);.
Class Method Details
.parent_pid(pid) ⇒ Integer?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
libproc.h:
int proc_pidinfo(int pid, int flavor, uint64_t arg, void *buffer, int buffersize);
Unlike PROC_PIDTBSDINFO, this flavor is not restricted to processes
owned by the current user, so the walk can pass through e.g. the
root-owned login between the shell and its terminal.
Returns nil if the process does not exist or cannot be inspected.
Returns 0 for launchd, which has no parent.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'os/mac/ffi/libproc.rb', line 36 def self.parent_pid(pid) buffer = Fiddle::Pointer.malloc(PROC_BSDSHORTINFO_SIZE, Fiddle::RUBY_FREE) size = function( "proc_pidinfo", [Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_UINT64_T, Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT], Fiddle::TYPE_INT, ).call(pid, PROC_PIDT_SHORTBSDINFO, 0, buffer, PROC_BSDSHORTINFO_SIZE) return if size != PROC_BSDSHORTINFO_SIZE buffer[PROC_BSDSHORTINFO_PPID_OFFSET, Fiddle::SIZEOF_INT].unpack1("L") end |