procreg

package
v0.7.3 Latest Latest
Warning

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

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

Documentation

Overview

Package procreg is the saved worker registry (ADR-0167): the process driver and the dev catalog engine record every process they start, so the next open reaps what a crashed run left behind. An entry is reaped only when the live pid's start time and boot match it (ADR-0187), so a reused pid is never signalled.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alive added in v0.7.0

func Alive(e Entry) bool

Alive reports whether e's process is ours and still runs: a zombie counts as gone.

func BootID added in v0.7.0

func BootID() (string, error)

BootID reads the boot ID an owner records next to the start time: Linux boot_id, read once; "" on macOS.

func Owned

func Owned(e Entry) bool

Owned reports whether e's pid still names the process its owner started, from facts the process cannot rewrite: the start time and the boot match (ADR-0187). Any read error means "not ours".

func StartTime

func StartTime(pid int) (uint64, error)

StartTime reads the OS start time of pid, which an owner records right after it starts a process.

Types

type Entry

type Entry struct {
	ID        string   `json:"id"`
	PID       int      `json:"pid"`
	PGID      int      `json:"pgid"`
	StartTime uint64   `json:"startTime"`        // OS-native: clock ticks since boot (Linux), µs since epoch (macOS)
	BootID    string   `json:"bootID,omitempty"` // Linux boot_id at save; "" on macOS and in entries of earlier releases
	Token     string   `json:"token"`            // still in argv; checked only for a Linux entry without BootID
	Files     []string `json:"files"`            // driver-owned temp files deleted at reap
}

Entry is one process a registry owner started.

type Registry

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

Registry is the saved set of entries in <dir>/<name>.json, owned by one process through the lock on <dir>/<name>.lock. It has no mutex of its own: the caller serializes Put, Delete and Close.

func Open

func Open(dir, name string) (*Registry, error)

Open takes the registry at <dir>/<name>.json, creating dir, and loads its entries. It fails with fault.Conflict while another owner holds the lock.

func (*Registry) Close

func (r *Registry) Close() error

Close empties the registry and releases the lock; a second Close does nothing.

func (*Registry) Delete

func (r *Registry) Delete(id string) error

Delete forgets the entry with id.

func (*Registry) Put

func (r *Registry) Put(e Entry) error

Put records e, replacing the entry with its ID.

func (*Registry) Reap

func (r *Registry) Reap(ctx context.Context, grace time.Duration) (killed int, err error)

Reap ends every saved process that is still ours: SIGTERM to each owned process group, up to grace for all of them together, then SIGKILL to the ones still owned. A group whose leader exits, or is a zombie, gets SIGKILL at once, as a worker's exit does (ADR-0011 C4): its other members outlive the leader, and its pgid is not reused while one lives. It deletes every entry's files, owned or not, and empties the registry. killed counts the process groups it signalled.

Jump to

Keyboard shortcuts

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