procstate

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package procstate reads process state from a procfs.

It exists as its own package so that the callers which need it are not obliged to make raw path-based reads inside packages whose own reads are held to directory-bound primitives.

The root is a parameter, so what gets read is the caller's choice and this package makes no claim about it. The production caller supplies a kernel filesystem; the reads here are not bound against an operator-writable tree and must not be pointed at one.

The package carries no build constraint, so that a platform without a procfs can still build and import it. There the read fails and the state is reported unavailable, which is what callers must handle in any case.

Index

Constants

View Source
const (
	Zombie     = 'Z'
	Dead       = 'X'
	DeadLegacy = 'x'
)

The procfs state letters treated as meaning the process has exited. Field 3 of proc_pid_stat(5) defines Z for a process awaiting collection by its parent and X for one that is dead; older kernels spelled the latter lowercase x, which is accepted here because accepting it costs nothing.

Every other letter, including one this package does not recognize, is treated as not exited. That is the conservative direction: it can delay noticing that a process has finished, but it cannot declare a live one dead. T and t in particular are stopped rather than finished.

Variables

This section is empty.

Functions

func IsTerminal

func IsTerminal(state byte) bool

IsTerminal reports whether state is one of the procfs letters that mean the process has exited. Every other letter is not terminal.

func State

func State(root string, pid int) (byte, bool)

State returns the single-letter state of pid as recorded under root, and whether it could be read at all. The root is a parameter so the parsing can be exercised against a fixture on a host that has no procfs of its own.

Types

This section is empty.

Jump to

Keyboard shortcuts

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