cgroups.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package cgroups
  2. import (
  3. "github.com/opencontainers/runc/libcontainer/configs"
  4. )
  5. type Manager interface {
  6. // Apply creates a cgroup, if not yet created, and adds a process
  7. // with the specified pid into that cgroup. A special value of -1
  8. // can be used to merely create a cgroup.
  9. Apply(pid int) error
  10. // GetPids returns the PIDs of all processes inside the cgroup.
  11. GetPids() ([]int, error)
  12. // GetAllPids returns the PIDs of all processes inside the cgroup
  13. // any all its sub-cgroups.
  14. GetAllPids() ([]int, error)
  15. // GetStats returns cgroups statistics.
  16. GetStats() (*Stats, error)
  17. // Freeze sets the freezer cgroup to the specified state.
  18. Freeze(state configs.FreezerState) error
  19. // Destroy removes cgroup.
  20. Destroy() error
  21. // Path returns a cgroup path to the specified controller/subsystem.
  22. // For cgroupv2, the argument is unused and can be empty.
  23. Path(string) string
  24. // Set sets cgroup resources parameters/limits. If the argument is nil,
  25. // the resources specified during Manager creation (or the previous call
  26. // to Set) are used.
  27. Set(r *configs.Resources) error
  28. // GetPaths returns cgroup path(s) to save in a state file in order to
  29. // restore later.
  30. //
  31. // For cgroup v1, a key is cgroup subsystem name, and the value is the
  32. // path to the cgroup for this subsystem.
  33. //
  34. // For cgroup v2 unified hierarchy, a key is "", and the value is the
  35. // unified path.
  36. GetPaths() map[string]string
  37. // GetCgroups returns the cgroup data as configured.
  38. GetCgroups() (*configs.Cgroup, error)
  39. // GetFreezerState retrieves the current FreezerState of the cgroup.
  40. GetFreezerState() (configs.FreezerState, error)
  41. // Exists returns whether the cgroup path exists or not.
  42. Exists() bool
  43. // OOMKillCount reports OOM kill count for the cgroup.
  44. OOMKillCount() (uint64, error)
  45. }