package cgroup import ( "fmt" "os" "path/filepath" "strconv" "linkfog.com/public/lib/l" "linkfog.com/public/option" ) var HostCgroupCfg string func SetHostCgroup() (err error) { if HostCgroupCfg != "" { return nil } for i := 1; i < 10; i++ { HostCgroupCfg, err = GetCgroup(i) if err != nil { l.Info(getCgroupPath(i), err) continue } return nil } return fmt.Errorf("set host cgroup err") } func IsContainerCgroup(cgroup string) bool { if HostCgroupCfg == "" || cgroup == "" { return false } return cgroup != HostCgroupCfg } func GetCgroup(pid int) (string, error) { cgroup, err := os.ReadFile(getCgroupPath(pid)) if err != nil { return "", err } return string(cgroup), nil } func getCgroupPath(pid int) string { return filepath.Join(option.HostProc, strconv.Itoa(pid), "cgroup") }