How to stop a Linux process for later execution swapping-out its memory
You might look into a technique called checkpoint/restore. This will allow you to take a running process and save its state to a set of files, then restore it at a later time.
To use it, start by installing the criu [git,wiki] program (yum install criu
or apt install criu
).
To checkpoint a running process, create an empty directory to hold its files and cd into that directory.
mkdir /var/tmp/checkpoint
cd /var/tmp/checkpoint
Now checkpoint the running process. In this case I'm using the --shell-job since I have my process running in a shell with an associated tty.
criu dump -t 404 --shell-job
404 is the pid of the process I want to checkpoint. When I do this I see my running process get killed and my /var/tmp/checkpoint directory get populated with a set of files needed to restore it.
To restore the process, I make sure I'm in the directory with the checkpoint files and do a restore.
cd /var/tmp/checkpoint
criu restore --shell-job
The process will pick up where it left off in the terminal where this was run. If I kill this running process and run criu restore --shell-job
again, the process will revert back to the checkpoint and start up again.
Hope this helps.