cgroup

package
v0.3.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package cgroup reads CPU and memory resource limits from Linux control groups (cgroup v2).

References:

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoLimit indicates that no cgroup limit is set.
	ErrNoLimit = errors.New("no cgroup limit set")

	// ErrV1Detected indicates that cgroup v1 controllers were found. Only v2 is
	// supported.
	ErrV1Detected = errors.New("cgroup v1 detected; only v2 is supported")
)

Errors.

Functions

This section is empty.

Types

type Cgroup

type Cgroup struct {
	// contains filtered or unexported fields
}

Cgroup provides access to cgroup v2 resource limits. Create one with New or NewFromRoot.

func New

func New() (Cgroup, error)

New returns a Cgroup by reading /proc/self/cgroup on the live system.

func NewFromRoot

func NewFromRoot(root string) (Cgroup, error)

NewFromRoot is like New but resolves all filesystem paths relative to root instead of "/". This is useful for testing with a mock filesystem.

func (Cgroup) CPUQuota

func (c Cgroup) CPUQuota() (float64, error)

CPUQuota returns the CPU quota as a fractional number of CPUs (e.g. 0.5 means half a core). Returns ErrNoLimit if no CPU limit is configured.

func (Cgroup) MemoryLimit

func (c Cgroup) MemoryLimit() (int64, error)

MemoryLimit returns the cgroup memory limit in bytes. Returns ErrNoLimit if no memory limit is configured.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL