How to “hibernate” a process in Linux by storing i

2019-01-07 04:31发布

Is it possible to 'hibernate' a process in linux? Just like 'hibernate' in laptop, I would to write all the memory used by a process to disk, free up the RAM. And then later on, I can 'resume the process', i.e, reading all the data from memory and put it back to RAM and I can continue with my process?

13条回答
闹够了就滚
2楼-- · 2019-01-07 04:46

Ctrl-Z increases the chances the process's pages will be swapped, but it doesn't free the process's resources completely. The problem with freeing a process's resources completely is that things like file handles, sockets are kernel resources the process gets to use, but doesn't know how to persist on its own. So Ctrl-Z is as good as it gets.

查看更多
冷血范
3楼-- · 2019-01-07 04:50

I used to maintain CryoPID, which is a program that does exactly what you are talking about. It writes the contents of a program's address space, VDSO, file descriptor references and states to a file that can later be reconstructed. CryoPID started when there were no usable hooks in Linux itself and worked entirely from userspace (actually, it still does work, depending on your distro / kernel / security settings).

Problems were (indeed) sockets, pending RT signals, numerous X11 issues, the glibc caching getpid() implementation amongst many others. Randomization (especially VDSO) turned out to be insurmountable for the few of us working on it after Bernard walked away from it. However, it was fun and became the topic of several masters thesis.

If you are just contemplating a program that can save its running state and re-start directly into that state, its far .. far .. easier to just save that information from within the program itself, perhaps when servicing a signal.

查看更多
姐就是有狂的资本
4楼-- · 2019-01-07 04:52

I extended Cryopid producing a package called Cryopid2 available from SourceForge. This can migrate a process as well as hibernating it (along with any open files and sockets - data in sockets/pipes is sucked into the process on hibernation and spat back into these when process is restarted).

The reason I have not been active with this project is I am not a kernel developer - both this (and/or the original cryopid) need to get someone on board who can get them running with the lastest kernels (e.g. Linux 3.x).

The Cryopid method does work - and is probably the best solution to general purpose process hibernation/migration in Linux I have come across.

查看更多
唯我独甜
5楼-- · 2019-01-07 04:57

I'd like to put a status update here, as of 2014.

The accepted answer suggests CryoPID as a tool to perform Checkpoint/Restore, but I found the project to be unmantained and impossible to compile with recent kernels. Now, I found two actively mantained projects providing the application checkpointing feature.

The first, the one I suggest 'cause I have better luck running it, is CRIU that performs checkpoint/restore mainly in userspace, and requires the kernel option CONFIG_CHECKPOINT_RESTORE enabled to work.

Checkpoint/Restore In Userspace, or CRIU (pronounced kree-oo, IPA: /krɪʊ/, Russian: криу), is a software tool for Linux operating system. Using this tool, you can freeze a running application (or part of it) and checkpoint it to a hard drive as a collection of files. You can then use the files to restore and run the application from the point it was frozen at. The distinctive feature of the CRIU project is that it is mainly implemented in user space.

The latter is DMTCP; quoting from their main page:

DMTCP (Distributed MultiThreaded Checkpointing) is a tool to transparently checkpoint the state of multiple simultaneous applications, including multi-threaded and distributed applications. It operates directly on the user binary executable, without any Linux kernel modules or other kernel modifications.

There is also a nice Wikipedia page on the argument: Application_checkpointing

查看更多
你好瞎i
6楼-- · 2019-01-07 04:57

This is sort of the ultimate goal of clustered operating system. Mathew Dillon puts a lot of effort to implement something like this in his Dragonfly BSD project.

查看更多
ら.Afraid
7楼-- · 2019-01-07 05:04

Linux Kernel has now partially implemented the checkpoint/restart futures:https://ckpt.wiki.kernel.org/, the status is here.

Some useful information are in the lwn(linux weekly net): http://lwn.net/Articles/375855/ http://lwn.net/Articles/412749/ ......

So the answer is "YES"

查看更多
登录 后发表回答