Help us shape the future of Go! Take the 2026 Go Developer Survey

procid

package
v1.37.1-stratum.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package procid answers one question for every /proc scanner in the tree: which live process is Stratum's, and which component does it belong to?

It owns the single /proc walk — one listing of procRoot yielding each live process's pid, argv and exe target, with one exited-process policy — and the per-component identity predicates built on it. The supervisor's legacy-handoff check, comps' liveness probes and staticpod's process scanners all walk through Walk and decide identity through these predicates, so a change to how a process is recognized happens in one place.

This is a leaf package: it imports version's path constants and nothing else from the tree, so any package may import it without a cycle.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildInfo

func BuildInfo(path string) (*buildinfo.BuildInfo, error)

BuildInfo reads the Go build information of the executable at path — normally /proc/<pid>/exe, whose symlink target the kernel keeps valid even after the binary is replaced. A valid native (non-Go) ELF image is not an error and returns nil: a native program may legitimately run an argument a scanner is matching on. A malformed or unreadable image is an error, so a caller deciding what to signal fails closed.

func Exited

func Exited(err error) bool

Exited reports a /proc read that failed because the process is gone: its directory was removed (ENOENT), or it is exiting and the kernel no longer serves its files (ESRCH). Gone is not an unreadable process table: such a read means skip, and every other error means the walk fails.

func HasArgv0Basename

func HasArgv0Basename(component string, p Process) bool

HasArgv0Basename reports whether the process runs the component by argv[0] basename alone, whatever path it runs from. This is the static-pod scanners' deliberately loose rule: the component runs as a container image's entrypoint with no staged host path, and a distro-owned same-named binary is still that component running on this node. A different basename is not.

func HasPayloadPath

func HasPayloadPath(component string, p Process) bool

HasPayloadPath reports whether the process runs the component's staged payload binary: argv[0] must be exactly the binary under BinDir. A distribution-owned binary with the same basename, or anything else under BinDir, is not the component, and a caller deciding what to signal must refuse it.

func IsOperator

func IsOperator(p Process) bool

IsOperator reports whether the process is the stratum operator, by its flag shape rather than its executable name, which may be a release artifact (for example stratum-linux-amd64): argv[0]'s basename is not a stable identity. Its kubeconfig is super-admin.conf, or admin.conf for a process an earlier release started. Every Stratum-owned flag must be present, in any order; any program without the full shape — another program's operator, another subcommand, or the pkill command itself — is refused. OperatorCommandLinePattern in comps is this predicate as a `pkill -f` regular expression, pinned to it by a test.

func IsRuntimeShim

func IsRuntimeShim(p Process) bool

IsRuntimeShim reports whether the process is a runtime-v2 shim serving Stratum's containerd. Shims outlive containerd and are attributed by the runtime socket, not their executable path (a distro can install the same binary), and only in either address form the shim accepts.

func IsStratumBuild

func IsStratumBuild(info *buildinfo.BuildInfo) bool

IsStratumBuild reports whether build information identifies a binary built from the Stratum module: as the main module, so a renamed binary keeps its identity, or as a dependency, so a distribution CLI embedding stratum still hosts it. A binary with no readable build information is not Stratum's.

func IsStratumTopLevel

func IsStratumTopLevel(p Process) bool

IsStratumTopLevel reports whether the process is the top-level `stratum up` process — the one a human or a systemd unit runs, parent of the supervisor that runs containerd/kubelet/operator in-process. Unlike containerd/kubelet, there is no staged path to match against: this binary can be running from anywhere (there is no equivalent of version.BinDir for it), and, like the operator, may be named after a release artifact rather than "stratum".

The up subcommand is decided by the same flag-skipping scan IsUpCommand runs (isUpSubcommand), which rules out this same binary's own "stratum uninstall" invocation, running as this very call — but is not identity by itself, since a distro-owned or third-party program with an "up" subcommand would match it too. What makes this specific is /proc/<pid>/exe resolving to the exact same file `stratum uninstall` itself is running from (os.Executable()): the two are normally the same binary. An unresolvable exe is not a match: better to leave a process alone than to signal one this call could not actually confirm.

The kernel appends " (deleted)" to that readlink's target once the underlying file is unlinked — an upgrade replacing the binary out from under a still-running `stratum up`, for example — so both sides are compared with that suffix stripped, or a routine upgrade would make this stop matching the exact process it most needs to find.

func IsUpCommand

func IsUpCommand(args []string) bool

IsUpCommand reports whether args selects the `up` subcommand, through the one stratum-up scan isUpSubcommand performs. The legacy-supervisor handoff check pairs it with IsStratumBuild: any binary built from the Stratum module running up counts. That is the deliberate difference from IsStratumTopLevel, which shares this scan and then requires the process's exe to be this very binary — a difference about whose up it is, never about what running up means.

func Walk

func Walk(procRoot string, visit func(Process) (bool, error)) error

Walk visits every live process under procRoot, in directory-listing order. Entries that are not processes — non-numeric names, numeric names that are not directories, kernel threads and zombies with an empty cmdline — never reach visit. A process that exits between the listing and its cmdline read is skipped; any other cmdline read error fails the walk, because a caller deciding what is safe to stop must not read an unreadable table as an empty one. visit returns whether to keep walking: false stops the walk after the process it answered, an error aborts it.

Types

type Process

type Process struct {
	PID  int
	Argv []string
	Exe  string
}

Process is one live process as the walk yields it. Exe is the /proc/<pid>/exe symlink's target, empty when it could not be read — the process may have exited between the cmdline read and the readlink, or the reader may not own the process. A predicate that needs Exe treats empty as "cannot confirm", never as a match.

Jump to

Keyboard shortcuts

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