Operations 3 min read

How to Use CRIU for Linux Process Checkpoint and Restore with Node.js

Learn how to install CRIU on CentOS, create a simple Node.js program that prints its PID, capture its state with a checkpoint using CRIU, and then restore the process, demonstrating practical use cases like migration and fast startup.

Node Underground
Node Underground
Node Underground
How to Use CRIU for Linux Process Checkpoint and Restore with Node.js

CRIU (Checkpoint/Restore In Userspace) is a Linux userspace tool that can checkpoint and restore processes, enabling scenarios such as hot migration, startup acceleration, and debugging.

Install CRIU

On CentOS 7, installation is straightforward:

yum install criu

Write a Test Node.js Program

Create index.js in ~/test. The program prints its PID and an incrementing number every second:

let idx = 0;
(async () => {
  while (true) {
    console.log(process.pid, idx++);
    await sleep(1000);
  }
})().catch(console.error);

function sleep(n) {
  return new Promise(resolve => {
    setTimeout(resolve, n);
  });
}

Running the program produces output like:

node test.js
3501 0
3501 1
3501 2
...

Create a Snapshot

Assuming the process PID is 3501, create a checkpoint snapshot: criu dump -j -t 3501 -D ~/testSnapshot The -j flag indicates shell jobs, -t specifies the target PID, and -D sets the directory where the snapshot is stored. After the dump, the process terminates.

Restore the Process

To restore the checkpointed process, run: criu restore -j -D ~/testSnapshot The process resumes with the counter continuing from its previous value, e.g.:

3501 37
3501 38
...

Conclusion

This simple example demonstrates CRIU's capability to checkpoint and restore a running Node.js process, illustrating its potential for use cases such as process migration and rapid startup. For more details, see the original article "Usage scenarios‑CRIU".

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Node.jsLinuxCheckpointprocess migration
Node Underground
Written by

Node Underground

No language is immortal—Node.js isn’t either—but thoughtful reflection is priceless. This underground community for Node.js enthusiasts was started by Taobao’s Front‑End Team (FED) to share our original insights and viewpoints from working with Node.js. Follow us. BTW, we’re hiring.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.