Class: RealUser::ProcFs
- Inherits:
-
Object
- Object
- RealUser::ProcFs
- Defined in:
- lib/realuser.rb
Overview
The `ProcFs` class interacts with the `/proc` filesystem to fetch information about the real user ID (RUID) and parent process ID (PPID) of a given process.
Class Method Summary collapse
-
.ppid(pid = Process.pid) ⇒ Integer?
Retrieves the parent process ID (PPID) of the process specified by `pid`.
-
.ruid(pid = Process.pid) ⇒ Integer?
Retrieves the real user ID (RUID) of the process specified by `pid`.
Class Method Details
.ppid(pid = Process.pid) ⇒ Integer?
Retrieves the parent process ID (PPID) of the process specified by `pid`. Defaults to the current process ID if none is provided.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/realuser.rb', line 56 def self.ppid(pid = Process.pid) @ppid_cache ||= {} key = pid.to_s.to_sym result = @ppid_cache[key] return result if result result = File.read("/proc/#{pid}/status").match(/^PPid:\s+(\d+)/)[1].to_i @ppid_cache[key] = result result rescue @ppid_cache[key] = nil nil end |
.ruid(pid = Process.pid) ⇒ Integer?
Retrieves the real user ID (RUID) of the process specified by `pid`. Defaults to the current process ID if none is provided.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/realuser.rb', line 36 def self.ruid(pid = Process.pid) @ruid_cache ||= {} key = pid.to_s.to_sym result = @ruid_cache[key] return result if result result = File.stat("/proc/#{pid}").uid @ruid_cache[key] = result result rescue @ruid_cache[key] = nil nil end |