relimit

package module
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

README

relimit

Relimit is a tool that limits the CPU and memory usage of a process.(cpu和内存使用限制工具)

Usage
import (
 "fmt"
 "github.com/realjf/cgroup"
)

func main() {
 re := MustNewRelimit(30, 8*cgroup.Megabyte, true)
 defer re.Close()
 args := []string{"--cpu", "1", "--vm", "1", "--vm-bytes", "20M", "--timeout", "10s", "--vm-keep"}
 out, err := re.Start("stress", args...)
 if err != nil {
   fmt.Println(err.Error())
 }
 fmt.Printf("output: %s\n", out)
}

Please use it as root or sudo.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandomGroup

func RandomGroup() string

func RandomName

func RandomName() string

func RandomSlice

func RandomSlice() string

Types

type IReLimit

type IReLimit interface {
	Start(cmdl string, args ...string) (output []byte, err error)
	Close()
	SetDebug(debug bool)
	GetCmd() *utils.Command
	GetCgroup() cgroup.ICgroup
	StartByPid(pid int) error
	SetUsername(username string) error
	SetUser(user *user.User) IReLimit
	SetNoSetGroups(noSetGroups bool)
}

func MustNewRelimit

func MustNewRelimit(maxCpuUsage cgroup.Percent, maxMemoryInBytes cgroup.Memory, disableOOMKill bool) IReLimit

func NewRelimit

func NewRelimit(maxCpuUsage cgroup.Percent, maxMemoryInBytes cgroup.Memory, disableOOMKill bool) (IReLimit, error)

Jump to

Keyboard shortcuts

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