procscanner

package
v2.13.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: GPL-3.0 Imports: 10 Imported by: ? 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

Overview

Package procscanner provides a shared process scanner for monitoring multiple types of processes with a single /proc scan.

Index

Constants

View Source
const (
	// DefaultPollInterval is the default polling interval for process scanning.
	DefaultPollInterval = 2 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AndMatcher

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

AndMatcher combines multiple matchers with AND logic.

func NewAndMatcher

func NewAndMatcher(matchers ...Matcher) *AndMatcher

NewAndMatcher creates a matcher that requires all sub-matchers to match.

func (*AndMatcher) Match

func (m *AndMatcher) Match(proc ProcessInfo) bool

Match returns true if all sub-matchers match.

type Callbacks

type Callbacks struct {
	// OnStart is called when a matching process is detected.
	OnStart func(proc ProcessInfo)
	// OnStop is called when a tracked process exits.
	OnStop func(pid int)
}

Callbacks contains the callbacks for process lifecycle events.

type CmdlineContainsMatcher

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

CmdlineContainsMatcher matches processes whose cmdline contains a substring.

func NewCmdlineContainsMatcher

func NewCmdlineContainsMatcher(substring string) *CmdlineContainsMatcher

NewCmdlineContainsMatcher creates a matcher that checks if cmdline contains a substring.

func (*CmdlineContainsMatcher) Match

func (m *CmdlineContainsMatcher) Match(proc ProcessInfo) bool

Match returns true if the process cmdline contains the substring.

type CommMatcher

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

CommMatcher matches processes by their comm name (case-insensitive).

func NewCommMatcher

func NewCommMatcher(names []string) *CommMatcher

NewCommMatcher creates a matcher that matches any of the given process names.

func (*CommMatcher) Match

func (m *CommMatcher) Match(proc ProcessInfo) bool

Match returns true if the process comm matches any registered name.

type ExactCommMatcher

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

ExactCommMatcher matches processes by exact comm name (case-sensitive).

func NewExactCommMatcher

func NewExactCommMatcher(name string) *ExactCommMatcher

NewExactCommMatcher creates a matcher for an exact process name.

func (*ExactCommMatcher) Match

func (m *ExactCommMatcher) Match(proc ProcessInfo) bool

Match returns true if the process comm exactly matches.

type Matcher

type Matcher interface {
	// Match returns true if this process should be tracked.
	Match(proc ProcessInfo) bool
}

Matcher determines if a process should be tracked.

type MatcherFunc

type MatcherFunc func(proc ProcessInfo) bool

MatcherFunc is a function adapter for Matcher interface.

func (MatcherFunc) Match

func (f MatcherFunc) Match(proc ProcessInfo) bool

Match implements Matcher.

type Option

type Option func(*Scanner)

Option configures a Scanner.

func WithPollInterval

func WithPollInterval(d time.Duration) Option

WithPollInterval sets the polling interval for process scanning.

func WithProcPath

func WithProcPath(path string) Option

WithProcPath sets a custom /proc path (for testing).

type OrMatcher

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

OrMatcher combines multiple matchers with OR logic.

func NewOrMatcher

func NewOrMatcher(matchers ...Matcher) *OrMatcher

NewOrMatcher creates a matcher that requires any sub-matcher to match.

func (*OrMatcher) Match

func (m *OrMatcher) Match(proc ProcessInfo) bool

Match returns true if any sub-matcher matches.

type ProcessInfo

type ProcessInfo struct {
	Comm    string
	Cmdline string
	PID     int
}

ProcessInfo contains information about a running process.

type Scanner

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

Scanner monitors /proc for processes and notifies registered watchers.

func New

func New(opts ...Option) *Scanner

New creates a new process scanner.

func (*Scanner) Start

func (s *Scanner) Start() error

Start begins monitoring for processes.

func (*Scanner) Stop

func (s *Scanner) Stop()

Stop stops the scanner and waits for goroutines to finish.

func (*Scanner) Unwatch

func (s *Scanner) Unwatch(id WatchID)

Unwatch removes a registered watcher.

func (*Scanner) Watch

func (s *Scanner) Watch(m Matcher, cb Callbacks) WatchID

Watch registers a watcher to be notified when matching processes start/stop. Returns a WatchID that can be used to unregister the watcher.

type WatchID

type WatchID int

WatchID uniquely identifies a registered watcher.

Jump to

Keyboard shortcuts

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