浏览代码

Merge pull request #8931 from vbatts/vbatts-mount_pid_mountinfo

pkg/mount: mountinfo from specified pid
Alexandr Morozov 10 年之前
父节点
当前提交
349f67632f
共有 1 个文件被更改,包括 13 次插入0 次删除
  1. 13 0
      pkg/mount/mountinfo_linux.go

+ 13 - 0
pkg/mount/mountinfo_linux.go

@@ -1,3 +1,5 @@
+// +build linux
+
 package mount
 
 import (
@@ -72,3 +74,14 @@ func parseInfoFile(r io.Reader) ([]*MountInfo, error) {
 	}
 	return out, nil
 }
+
+// PidMountInfo collects the mounts for a specific Pid
+func PidMountInfo(pid int) ([]*MountInfo, error) {
+	f, err := os.Open(fmt.Sprintf("/proc/%d/mountinfo", pid))
+	if err != nil {
+		return nil, err
+	}
+	defer f.Close()
+
+	return parseInfoFile(f)
+}