This page describes the high-level design and internal mechanics of the Checkpoint and Restore processes in CRIU.
The checkpoint procedure captures the full state of a process tree. It combines information from the Linux kernel’s /proc filesystem with data extracted directly from the processes’ address space.
CRIU begins by identifying the process group leader (via the --tree option) and recursively collecting all threads and children. To ensure a consistent snapshot, the entire tree must be “frozen.”
PTRACE_SEIZE followed by PTRACE_INTERRUPT to stop tasks without delivering signals that could be visible to the application.CRIU gathers state that the kernel exposes via /proc:
/proc/$pid/fdinfo (which includes positions and flags)./proc/$pid/smaps and /proc/$pid/map_files./proc/$pid/stat.Some state (like memory contents and specific credentials) can only be captured from within the process. CRIU uses a technique called parasite injection:
ptrace to inject a small bit of code into the task’s instruction stream (at the current CS:IP).mmap syscall to allocate space for the full parasite blob.Once the state is captured, CRIU uses ptrace to remove the parasite code and restore the original instructions. The processes are then either resumed or killed, depending on the command-line options.
The restore procedure is essentially the reverse of a checkpoint. CRIU “morphs” itself into the process tree it is restoring through a multi-stage process.
CRIU analyzes the image files to identify resources shared between processes (e.g., shared memory segments, pipes, or inherited file descriptors). It determines which process will “create” the resource and how others will “inherit” it.
CRIU calls fork() repeatedly to recreate the original process hierarchy. To restore specific PIDs, it uses the ns_last_pid interface or the clone3 system call. At this stage, only process leaders are created; threads are restored later.
Each process in the new tree begins restoring its environment:
To restore the final memory layout, CRIU must unmap its own code and data. This requires a restorer blob:
mmap and munmap calls.The very last step of the restorer is to call sigreturn. CRIU prepares a special signal frame on the stack that contains the original register state (including the instruction pointer) of the process at the time of the checkpoint. The sigreturn syscall tells the kernel to load this state and resume execution of the application code.
See also: Restorer Context, Tree After Restore