Module: DockerPid::Host
- Defined in:
- lib/docker_pid.rb
Class Method Summary collapse
Class Method Details
.docker_container_id(pid) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/docker_pid.rb', line 31 def self.docker_container_id(pid) cg = proc_cgroup(pid) m = cg.match(/\/docker\/(.+?)(\/|\n)/m) raise NotDockerProcess.new("PID: #{pid}") if m.nil? m[1] end |
.exist_process?(pid) ⇒ Boolean
12 13 14 15 16 17 18 19 |
# File 'lib/docker_pid.rb', line 12 def self.exist_process?(pid) begin Process.getpgid(pid) true rescue Errno::ESRCH false end end |
.proc_cgroup(pid) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/docker_pid.rb', line 21 def self.proc_cgroup(pid) begin p = Integer(pid) raise unless exist_process?(p) rescue => e raise ProcessNotExist.new("PID: #{pid}") end File.read("/proc/#{pid}/cgroup") end |