Skip to content

Instantly share code, notes, and snippets.

@salotz
Created March 20, 2019 21:20
Show Gist options
  • Save salotz/6d01c4a7c126a7857bd62e17e3f5dad0 to your computer and use it in GitHub Desktop.
Save salotz/6d01c4a7c126a7857bd62e17e3f5dad0 to your computer and use it in GitHub Desktop.
CRIU as a interactive terminal session manager with disk persistence

First start an ipython session first printing out the PID.

bash -c "echo $$; exec ipython"

I also tried changing the name of the process so you can name them but it didn’t seem to work, although there is probably something you can do to be able to do this:

bash -c "echo $$; exec -a sessionname ipython"

In that case you would’nt really even need the PID:

bash -c "exec -a sessionname ipython"

Then we use CRIU to checkpoint it:

If we can rename it:

sudo criu dump -D session_image_dir -o dump.log -t $(pgrep "sessionname")

If we can’t just use the PID

bash -c "session_pid=$$; exec ipython"
sudo criu dump --shell-job -D session_image_dir -o dump.log -t ${session_pid}

The files should be in the session_image_dir, along with the log.

Then to get it back:

sudo criu restore --shell-job -D session_image_dir -o restore.log

Then you just need to refresh the terminal emulator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment