Linux command
criu 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Check
criu check
Checkpoint
sudo criu dump -t [pid] -D [path/to/image_dir] --shell-job
Checkpoint
sudo criu dump -t [pid] -D [path/to/image_dir] --tcp-established --leave-running
Restore
sudo criu restore -D [path/to/image_dir] --shell-job
Restore
sudo criu restore -D [path/to/image_dir] -d
Serve memory pages
sudo criu page-server -D [path/to/image_dir] --port [1234]
说明
criu ("Checkpoint and Restore In Userspace") freezes a running Linux application — or an entire container — and serializes its complete state to a set of image files. Memory, open file descriptors, pipes, sockets, namespaces, and cgroup membership are all captured. A later criu restore recreates equivalent processes from those images, optionally on a different host, so the application resumes execution where it left off. The bulk of the work happens in userspace. CRIU seizes a process tree via ptrace, injects a small "parasite" code module (libcompel) to read the process's address space, and writes everything out to the configured image directory. Restore reverses the procedure: it rebuilds namespaces, recreates file descriptors, maps memory, and finally returns control to the original program counter. CRIU is the foundation for live migration in OpenVZ, LXC/LXD, and Podman, and is used by runc and Kubernetes to snapshot and migrate containers. It also enables faster cold starts by warming up an application and resuming from the checkpoint on demand.
参数
- -t, --tree _pid_
- PID of the root task to dump.
- -D, --images-dir _dir_
- Directory where image files are stored or read from.
- -W, --work-dir _dir_
- Directory for log and working files (defaults to the images directory).
- -v_n_, --verbosity
- Set verbosity level (repeatable).
- -R, --leave-running
- Leave the task running after a successful dump.
- -s, --leave-stopped
- Leave the tasks stopped after dump (useful for live migration).
- --tcp-established
- Checkpoint and restore established TCP connections.
- --shell-job
- Allow checkpoint/restore of shell jobs (controlling terminal handling).
- --manage-cgroups
- Save and restore cgroup configuration with the process.
- -d, --restore-detached
- Detach from the restored process tree on success.
- --display-stats
- Print dump or restore statistics on completion.
FAQ
What is the criu command used for?
criu ("Checkpoint and Restore In Userspace") freezes a running Linux application — or an entire container — and serializes its complete state to a set of image files. Memory, open file descriptors, pipes, sockets, namespaces, and cgroup membership are all captured. A later criu restore recreates equivalent processes from those images, optionally on a different host, so the application resumes execution where it left off. The bulk of the work happens in userspace. CRIU seizes a process tree via ptrace, injects a small "parasite" code module (libcompel) to read the process's address space, and writes everything out to the configured image directory. Restore reverses the procedure: it rebuilds namespaces, recreates file descriptors, maps memory, and finally returns control to the original program counter. CRIU is the foundation for live migration in OpenVZ, LXC/LXD, and Podman, and is used by runc and Kubernetes to snapshot and migrate containers. It also enables faster cold starts by warming up an application and resuming from the checkpoint on demand.
How do I run a basic criu example?
Run `criu check` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -t, --tree _pid_ do in criu?
PID of the root task to dump.