process

package
v0.0.0-...-36c55c0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package process provides process management operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Darwin

type Darwin struct{}

Darwin implements the Provider interface for Darwin (macOS). All methods return ErrUnsupported as process management is not available on macOS.

func NewDarwinProvider

func NewDarwinProvider() *Darwin

NewDarwinProvider factory to create a new Darwin instance.

func (*Darwin) Get

func (d *Darwin) Get(
	_ context.Context,
	_ int,
) (*Info, error)

Get returns ErrUnsupported on Darwin.

func (*Darwin) List

func (d *Darwin) List(
	_ context.Context,
) ([]Info, error)

List returns ErrUnsupported on Darwin.

func (*Darwin) Signal

func (d *Darwin) Signal(
	_ context.Context,
	_ int,
	_ string,
) (*SignalResult, error)

Signal returns ErrUnsupported on Darwin.

type Debian

type Debian struct {
	provider.FactsAware
	// contains filtered or unexported fields
}

Debian implements the Provider interface for Debian-family systems.

func NewDebianProvider

func NewDebianProvider(
	logger *slog.Logger,
	lister Lister,
	signaler Signaler,
) *Debian

NewDebianProvider factory to create a new Debian instance.

func (*Debian) Get

func (d *Debian) Get(
	_ context.Context,
	pid int,
) (*Info, error)

Get returns details for a specific process by PID.

func (*Debian) List

func (d *Debian) List(
	_ context.Context,
) ([]Info, error)

List returns all running processes.

func (*Debian) Signal

func (d *Debian) Signal(
	_ context.Context,
	pid int,
	signal string,
) (*SignalResult, error)

Signal sends a signal to a process by PID.

type Info

type Info struct {
	PID        int     `json:"pid"`
	Name       string  `json:"name"`
	User       string  `json:"user"`
	State      string  `json:"state"`
	CPUPercent float64 `json:"cpu_percent"`
	MemPercent float32 `json:"mem_percent"`
	MemRSS     int64   `json:"mem_rss"`
	Command    string  `json:"command"`
	StartTime  string  `json:"start_time"`
}

Info represents a running process.

type Item

type Item struct {
	PID     int32
	Querier Querier
}

Item pairs a PID with a Querier. PID is exposed separately because gopsutil.Process.Pid is a struct field, which interfaces cannot express.

type Linux

type Linux struct{}

Linux implements the Provider interface for generic Linux. All methods return ErrUnsupported as this is a generic Linux stub.

func NewLinuxProvider

func NewLinuxProvider() *Linux

NewLinuxProvider factory to create a new Linux instance.

func (*Linux) Get

func (l *Linux) Get(
	_ context.Context,
	_ int,
) (*Info, error)

Get returns ErrUnsupported on generic Linux.

func (*Linux) List

func (l *Linux) List(
	_ context.Context,
) ([]Info, error)

List returns ErrUnsupported on generic Linux.

func (*Linux) Signal

func (l *Linux) Signal(
	_ context.Context,
	_ int,
	_ string,
) (*SignalResult, error)

Signal returns ErrUnsupported on generic Linux.

type Lister

type Lister interface {
	Processes() ([]Item, error)
	NewProcess(pid int32) (Querier, error)
}

Lister provides methods to list and look up processes.

func NewGopsutilLister

func NewGopsutilLister() Lister

NewGopsutilLister returns the real gopsutil-backed Lister.

type Provider

type Provider interface {
	// List returns all running processes.
	List(ctx context.Context) ([]Info, error)
	// Get returns details for a specific process by PID.
	Get(ctx context.Context, pid int) (*Info, error)
	// Signal sends a signal to a process by PID.
	Signal(ctx context.Context, pid int, signal string) (*SignalResult, error)
}

Provider implements process management operations.

type Querier

type Querier interface {
	Name() (string, error)
	Username() (string, error)
	Status() ([]string, error)
	CPUPercent() (float64, error)
	MemoryPercent() (float32, error)
	MemoryInfo() (*gopsutil.MemoryInfoStat, error)
	Cmdline() (string, error)
	CreateTime() (int64, error)
}

Querier provides methods to query a single process. *gopsutil.Process satisfies this interface.

type SignalResult

type SignalResult struct {
	PID     int    `json:"pid"`
	Signal  string `json:"signal"`
	Changed bool   `json:"changed"`
	Error   string `json:"error,omitempty"`
}

SignalResult represents the outcome of sending a signal to a process.

type Signaler

type Signaler interface {
	Kill(pid int, sig syscall.Signal) error
}

Signaler sends signals to processes.

func NewSyscallSignaler

func NewSyscallSignaler() Signaler

NewSyscallSignaler returns the real syscall-backed Signaler.

Directories

Path Synopsis
Package mocks provides mock implementations for testing.
Package mocks provides mock implementations for testing.

Jump to

Keyboard shortcuts

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