criu

package
v2.0.0-beta.13 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 11 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 criu drives CRIU around a process tree: freeze it with pidfds, dump it with link remaps and an empty plugin directory (GPU state is cuda-checkpoint's business, never CRIU's), restore it left stopped in a fresh PID namespace, thaw it. The namespace's PID allocator is moved so a restored PID never collides with the receiver's own processes.

Index

Constants

View Source
const GhostLimit = 64 << 20

GhostLimit is how large a deleted-but-open file CRIU may carry inside its images instead of as a link remap next to the original.

View Source
const PIDFloor = 32768

PIDFloor is the first PID of a snapshotted tree. The donor namespace is moved there before the engine starts; a receiver keeps its own processes (PID 1, CRIU, helpers) below it.

View Source
const Timeout = 10 * time.Minute

Timeout bounds one CRIU invocation.

Variables

View Source
var ErrNotIsolated = errors.New("criu: refusing to move the PID allocator outside a container")

ErrNotIsolated is returned when a namespace-wide operation would touch the host's PID namespace.

Functions

func Dump

func Dump(ctx context.Context, program string, tree int, images, work string) error

Dump checkpoints the tree rooted at tree into images. CRIU kills the tree afterwards; the caller reaps it.

func DumpArgs

func DumpArgs(tree int, images, work string) []string

DumpArgs is the qualified dump invocation: shell job, file locks, external unix sockets, established TCP, link remaps for deleted files, and a plugin directory that is empty on purpose.

func PrepareRestorePIDs

func PrepareRestorePIDs(maxID int) error

PrepareRestorePIDs checks that nothing in the receiver namespace occupies a PID the dump needs and moves the allocator above the dumped tree, so CRIU's helpers never take a PID the tree wants back.

func PrepareWork

func PrepareWork(dir string) error

PrepareWork creates a fresh work directory with the empty plugin directory CRIU is pointed at. Reusing one would hide an older log.

func ReservePIDFloor

func ReservePIDFloor() error

ReservePIDFloor moves the namespace's PID allocator just below PIDFloor, so everything started after it gets a PID a receiver can honour.

func Restore

func Restore(ctx context.Context, program, images, work string) (int, error)

Restore brings images back, every task stopped, and returns the root PID.

func RestoreArgs

func RestoreArgs(images, work string) []string

RestoreArgs restores detached and leaves every task stopped, so the receiver can re-attach the GPUs before anything runs.

Types

type Frozen

type Frozen struct {
	Tree Tree
	// contains filtered or unexported fields
}

Frozen is a stopped tree held through pidfds, so a signal reaches the process it was meant for even if its PID has been reused.

func Freeze

func Freeze(ctx context.Context, root int) (*Frozen, error)

Freeze stops root and every descendant with SIGSTOP in rounds until no new process appears, then waits for every thread to be stopped. A process that forks between rounds is caught by the next one; a stopped process cannot fork at all.

func RestoreStopped

func RestoreStopped(ctx context.Context, program, images, work string, expectedRoot, maxID int) (*Frozen, error)

RestoreStopped runs as PID 1 of a fresh namespace: it moves the PID allocator above the dumped tree, restores the images with every task left stopped, checks the root PID is the expected one and holds the tree through pidfds until Thaw.

func (*Frozen) Close

func (f *Frozen) Close() error

Close releases the pidfds. It never resumes or kills anything.

func (*Frozen) RootFD

func (f *Frozen) RootFD() int

RootFD is the pidfd of the tree's root; it becomes readable when the root exits.

func (*Frozen) Signal

func (f *Frozen) Signal(sig unix.Signal) error

Signal sends sig to the root.

func (*Frozen) Thaw

func (f *Frozen) Thaw(ctx context.Context) error

Thaw sends SIGCONT to every process. A process whose PID is gone is skipped.

type Process

type Process struct {
	PID     int    `json:"pid"`
	Parent  int    `json:"parent"`
	Threads []int  `json:"threads"`
	Start   string `json:"start"`
}

Process is one process of a tree with its threads and start ticks.

type Tree

type Tree struct {
	Root      int       `json:"root"`
	Processes []Process `json:"processes"`
}

Tree is a process and its descendants, root first, then by PID.

func VisibleTree

func VisibleTree(root int) (Tree, error)

VisibleTree is root and its descendants as /proc shows them now.

func (Tree) MaxID

func (t Tree) MaxID() int

MaxID is the highest PID or TID in the tree.

func (Tree) PIDs

func (t Tree) PIDs() []int

PIDs lists the processes in tree order.

Jump to

Keyboard shortcuts

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