cgroup

package
v0.0.0-...-86e9f11 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package cgroup implements a thin wrapper around the Linux cgroupv2 filesystem API. For more information, please consult the relevant kernel documentation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Move

func Move(pid int, into Dir) error

Move moves an existing process into the cgroup specified by into.

Types

type Dir

type Dir string

Dir is an absolute directory path (including the mount path of the cgroup2 mountpoint).

func Root

func Root() (Dir, error)

Root returns the first found cgroup2 mountpoint from /proc/mounts.

func Self

func Self() (Dir, error)

Self returns the cgroup of the current process, provided that the current process is *only* a member of a cgroup2 and not a legacy cgroup1 hierarchy.

func (Dir) Create

func (d Dir) Create(sub string, kill bool) (Dir, error)

Create creates a new directory sub under the existing group d. If the directory doesn't already exist, it is created. If the directory *does* exist, then the behavior of Create depends on the 'kill' flag: if kill is set to true, then all the sub-processes in the existing cgroup are killed. If kill is set to false, then an error is returned (matching fs.ErrExist) and the cgroup is left unmodified.

func (Dir) IsDelegated

func (d Dir) IsDelegated(uid, gid int) (bool, error)

IsDelegated returns (true, nil) if a process with the given uid+gid can add processes to d, or (false, nil) otherwise. IsDelegated will report an error if the cgroup doesn't exist.

func (Dir) IsZero

func (d Dir) IsZero() bool

IsZero returns true if d is the zero value of Dir. (The zero value of Dir is not a valid cgroup directory.)

func (Dir) Kill

func (d Dir) Kill() error

Kill kills all the processes in a cgroup. However, it does not remove the cgroup directory.

func (Dir) Procs

func (d Dir) Procs() ([]int, error)

Procs returns the list of pids that currently occupy a cgroup. (This corresponds to the cgroup.procs file within the cgroup directory.)

func (Dir) Remove

func (d Dir) Remove() error

Remove removes the cgroup. Only empty cgroups may be removed, so the caller may need to call Kill first in order to ensure the cgroup is empty.

func (Dir) Sub

func (d Dir) Sub(dir string) Dir

Sub returns a new Dir that represents a sub-directory of d.

func (Dir) WriteInt

func (d Dir) WriteInt(name string, val int) error

WriteInt writes the provided integer value plus a newline character to the file with the given name within d.

func (Dir) WriteLine

func (d Dir) WriteLine(name string, buf []byte) error

WriteLine writes the provided bytes plus a newline character to the file with the given name within d.

Jump to

Keyboard shortcuts

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