proc

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 4 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

Overview

Package proc identifies local processes by pid plus birth (start) time, so a pid the kernel reused is never taken for the process otag started, and finds their descendants. On macOS it reads the kernel's process table with sysctl (KERN_PROC); it never runs ps. Elsewhere only existence checks work and births are unknown.

A failed or implausible read is an error, never "the process exited": callers treat it as unknown and look again later.

Index

Constants

View Source
const TimeFormat = "2006-01-02T15:04:05.000Z"

TimeFormat is the layout of Birth; the same as db.TimeFormat (UTC, milliseconds).

Variables

View Source
var ErrUnsupported = errors.New("process table not readable on this system")

ErrUnsupported: the process table cannot be read on this system.

Functions

func All

func All() (map[int]Process, error)

All returns the whole process table by pid. A table that does not even contain this process is rejected as implausible.

func Ancestors

func Ancestors(all map[int]Process, pid int) map[int]bool

Ancestors returns pid and every ancestor of it in all (stopping at launchd).

func Birth

func Birth(pid int) string

Birth returns the start time of pid, "" when it cannot be read.

func Same

func Same(pid int, birth string) (bool, error)

Same reports whether pid still runs the process born at birth (a zombie does not count). An error means it could not be told.

func Signal

func Signal(p Process, sig syscall.Signal) (bool, error)

Signal sends sig to p if pid still runs the same process (p.Birth, when known), and to its process group as well when p leads one. pid 1 and below are never signalled. It reports whether p was still running.

Types

type Process

type Process struct {
	PID, PPID, PGID int
	UID             int    // effective user id; -1 when unknown
	Birth           string // start time (TimeFormat); "" when unknown
	Zombie          bool   // exited, not reaped yet: it runs no code any more
}

Process is one entry of the process table.

func Family

func Family(all map[int]Process, pid int, birth string) []Process

Family returns the processes that belong to the process otag started as pid, born at birth: while it runs, itself, its descendants and the members of its session; after it exited, the members of its session born after it. tmux makes every pane process a session leader (session id = its pid), and macOS never hands out a pid that is still in use as a session or group id, so while a member of that session is left no other process can get the pid. This finds children that were reparented to launchd when their parent died; one that left the session (setsid) is only found through its parent, while that runs. With birth "" (unknown) only a running pid is trusted, as the caller vouches for it (its pane still runs it).

func Get

func Get(pid int) (p Process, ok bool, err error)

Get returns process pid. ok is false only when the kernel says there is no such process; any other failure is an error (unknown).

func Tree

func Tree(all map[int]Process, root int) []Process

Tree returns root and every descendant of it in all (by parent links), root first. Births are taken from the same snapshot, so the result can be verified later with Same.

Jump to

Keyboard shortcuts

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