Before CRIU can begin checkpointing, it must ensure that the entire process tree is completely “immobilized.” This prevents tasks from changing their state (e.g., opening files, creating children, or receiving network packets) while the snapshot is being taken. This freezing process must be transparent to the application, meaning it should not observe any disruption or unexpected signals.
CRIU employs two primary methods to achieve this:
The most common method for freezing a tree is using the Linux ptrace interface. Unlike traditional debuggers that might send disruptive signals like SIGSTOP, CRIU uses a more modern, non-invasive approach:
ptrace(PTRACE_SEIZE, pid, ...) for every task in the tree. This “attaches” to the process without stopping it or delivering any signals.ptrace(PTRACE_INTERRUPT, pid, ...) command. This causes the kernel to stop the task at the next possible opportunity (typically upon entering or exiting a syscall or being preempted).TRAP_STOP state. This state is invisible to the task’s own signal handling logic, ensuring transparency.By seizing every task in the tree, CRIU ensures that no task can resume execution or fork new children during the dump.
For large process trees or environments where ptrace might be restricted or inefficient, CRIU can use the Linux Freezer CGroup. This allows the kernel to freeze an entire group of processes in a single, atomic operation.
CRIU supports both versions of the freezer:
FROZEN to the freezer.state file.FREEZING state. CRIU includes “kludges” to handle this, such as periodically retrying the freeze command or briefly thawing and re-freezing the group to kick the kernel’s internal state machine.1 to the cgroup.freeze file.cgroup.events file, waiting for the frozen 1 event to signal that all processes in the sub-hierarchy have successfully stopped.Note: Even when using a freezer cgroup, CRIU still attaches to the tasks via ptrace after they are frozen. This is necessary to perform internal inspections, such as extracting register states and injecting parasite code.