controller

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Rendered for windows/amd64

Index

Constants

View Source
const (
	EventKilled       = "controller.killed"
	EventSuspended    = "controller.suspended"
	EventResumed      = "controller.resumed"
	EventPriority     = "controller.priority"
	EventAffinity     = "controller.affinity"
	EventLimited      = "controller.limited"
	EventLimitCleared = "controller.limit_cleared"
)

Event names emitted on successful operations.

Variables

View Source
var (
	ErrProtected     = errors.New("process is protected")
	ErrCritical      = errors.New("process is marked critical by Windows")
	ErrConfirmNeeded = errors.New("operation requires explicit confirmation")
	ErrNotFound      = errors.New("process not found")
	ErrSelf          = errors.New("operation not allowed on the running Windows Task Manager process")
)

Common errors returned by the controller surface.

Functions

This section is empty.

Types

type Controller

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

Controller exposes process management operations with safety enforcement.

func NewController

func NewController(cfg *config.Config, store *storage.Store, emitter *event.Emitter) *Controller

func (*Controller) ActiveLimits

func (c *Controller) ActiveLimits() []LimitInfo

ActiveLimits returns a snapshot of every limited process.

func (*Controller) ClearLimit

func (c *Controller) ClearLimit(pid uint32) error

ClearLimit drops the Job Object for a PID, releasing its caps.

func (*Controller) Kill

func (c *Controller) Kill(pid uint32, confirm bool) error

Kill terminates a process. confirm is required for system paths when ConfirmKillSystem is enabled.

func (*Controller) KillTree

func (c *Controller) KillTree(rootPID uint32, confirm bool) (int, error)

KillTree terminates a process and every descendant. Each child must independently pass the safety check.

func (*Controller) Limit

func (c *Controller) Limit(pid uint32, cpuPct int, maxBytes uint64) error

Limit creates a Job Object around the PID and applies CPU/memory caps. cpuPct is 1..100 (0 disables CPU rate control); maxBytes is the working set / process memory cap (0 disables).

func (*Controller) Resume

func (c *Controller) Resume(pid uint32) error

Resume resumes every thread in a previously suspended process.

func (*Controller) SetAffinity

func (c *Controller) SetAffinity(pid uint32, mask uint64) error

SetAffinity restricts a process to a subset of logical CPUs.

func (*Controller) SetConfig

func (c *Controller) SetConfig(cfg *config.Config)

SetConfig hot-swaps the underlying safety config.

func (*Controller) SetPriority

func (c *Controller) SetPriority(pid uint32, class string) error

SetPriority maps a textual class to a Win32 priority class and applies it.

func (*Controller) Suspend

func (c *Controller) Suspend(pid uint32) error

Suspend pauses every thread in a process via SuspendThread.

type LimitInfo

type LimitInfo struct {
	PID      uint32 `json:"pid"`
	CPUPct   int    `json:"cpu_pct"`
	MemBytes uint64 `json:"mem_bytes"`
}

LimitInfo describes the active CPU/memory caps for a PID.

type Safety

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

Safety enforces the kill/suspend/limit policies declared in config.

func NewSafety

func NewSafety(cfg *config.Config) *Safety

func (*Safety) Check

func (s *Safety) Check(info metrics.ProcessInfo, forceConfirmed bool) error

Check verifies whether destructive action is allowed against `info`. `forceConfirmed` indicates the user has provided explicit confirmation for confirm-required cases.

func (*Safety) SetConfig

func (s *Safety) SetConfig(cfg *config.Config)

SetConfig swaps the active config (called on hot reload).

Jump to

Keyboard shortcuts

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