How to checkpoint and restore a Linux process

Suppose you have a Linux process running, and want to capture its current snapshot after freezing it. The frozen process is then loaded from the snapshot to resume. Such concept of process checkpointing can be very useful under a variety of circumstances. It can be used for process backup, live migration, faster boot-up service, etc. There is actually a user-space tool that can perform process checkpointing on Linux.

A Linux command-line utility called criu can checkpoint and restore processes in user space. criu can freeze a running process or process tree, dump its state as a set of files, and then restore the frozen process from the snapshot. For criu to work, there must be kernel support that exposes additional information about a Linux process. Fortunately, upstream Linux kernel 3.9 already has most of the required kernel support built into it. So you can easily run criu on kernel 3.9 and higher.

In this tutorial, I will show you how to checkpoint and restore a Linux process by using criu. I assume that you already have the Linux kernel 3.9 on your system.

To install criu on Ubuntu or Debian, install the following prerequisites first.

$ sudo apt-get install libprotobuf-dev libprotoc-dev protobuf-c-compiler libprotobuf-c0 libprotobuf-c0-dev

To build criu on Ubuntu or Debian:

$ wget
$ tar xvfvj crtools-0.5.tar.bz2
$ cd crtools-0.5
$ make

Once build is successful, it will generate a command line utility called crtools which is used to checkpoint and restore a Linux process.

To checkpoint a running process with crtools, run the following command. <PID> is the process ID of a running process. Once process checkpointing is successfully completed, the process will be terminated, and its state will be stored as a set of files in the current directory.

$ sudo ./crtools dump -t <PID>

To restore a dumped process to its original running state:

$ sudo ./crtools restore -t <PID>

Note that if the running process is launched directly from shell, you must use "--shell-job" option in crtools command as follows.

$ sudo ./crtools dump -t <PID> --shell-job
$ sudo ./crtools restore -t <PID> --shell-job

When restoring a process, the crtools command waits for the restored process to finish, and then exits. That is because when crtools restores a process, crtools becomes a parent process of the process.

If you want to make crtools return right after a process has been restored, use "--restore-detached" option as follows. A restored process will then be re-parented to init, so crtools can exit right away.

$ sudo ./crtools restore -t <PID> --shell-job --restore-detached

The criu also supports checkpoint/restart for a process which opens an active TCP connection. This feature takes advantage of sockets in "repair" mode, which is supported by the Linux kernel 3.5 and higher.

To checkpoint a process which has active TCP connection(s):

$ sudo ./crtools dump -t <PID> --tcp-established

To restore a process and its previously active TCP connection(s):

$ sudo ./crtools restore -t <PID> --tcp-established

Download this article as ad-free PDF (made possible by your kind donation): 
Download PDF

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

One thought on “How to checkpoint and restore a Linux process

  1. What kernel 3.9 are you referring to? I was unable to get all the required functionality until I built 3.11-rc1. I tried configuring all the previous mainline versions but CONFIG_MEM_SOFT_DIRTY was not available.

Leave a comment

Your email address will not be published. Required fields are marked *