Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "hibernate" a process in Linux by storing its memory to disk and restoring it later?

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?

like image 899
hap497 Avatar asked Jan 25 '10 18:01

hap497


People also ask

How does Linux hibernate?

Hibernate is an option that allows you to save your system state immediately to your hard disk, so that when you switch your computer on then all the programs can be restored from the hard disk and you can start working again with the same system state as you had before switching off, without losing any data.

What is Suspend to RAM in Linux?

Suspend-to-RAM This state (also referred to as STR or S2RAM), if supported, offers significant energy savings as everything in the system is put into a low-power state, except for memory, which should be placed into the self-refresh mode to retain its contents.


1 Answers

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.

like image 98
Tim Post Avatar answered Oct 14 '22 16:10

Tim Post