Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save a process' memory for later use?

Is it possible to pause a process, save the memory contents to a file, and then later reload the file so you can continue the program?

Edit I've been reading about this:

http://en.wikipedia.org/wiki/Setcontext

Is it possible to dump the contents of the struct, and somehow force malloc to allocate the same memory regions?

like image 972
Unknown Avatar asked Apr 03 '09 07:04

Unknown


People also ask

Do processes have their own memory?

Each process has its own memory space. Threads use the memory of the process they belong to. Inter-process communication is slow as processes have different memory addresses.

What is Process RAM?

RAM (Random Access Memory) is the hardware in a computing device where the operating system (OS), application programs and data in current use are kept so they can be quickly reached by the device's processor. RAM is the main memory in a computer.


4 Answers

Technically it is possible, but it would require saving all the system-allocated resources state too - like file descriptors for example and then restoring them. So it's a challenging task.

The easiest way to achieve what you want is to use a virtual machine like VMWare. When you pause it you actually save the whole machine state together with all programs running.

like image 177
sharptooth Avatar answered Oct 06 '22 10:10

sharptooth


This is usually called a persistent continuation. Some languages like SmallTalk and SBCL have first class support for persistent continuations. Most languages don't.

like image 23
Guillaume Avatar answered Oct 06 '22 10:10

Guillaume


Depending on your requirements and OS you could try forcing a core dump

I have never tried actually loading a core dumped program back up other than in gdb. It seems like any files you have open or any other state that is not in your programs memory would be lost as sharptooth pointed out.

Another approach would be simply serializing the state you need to disk in your program. It sucks but it is probably the most reliable way unless you are content with suspending execution of the program. That could be done with your operating system's thread library. Or as one poster pointed out with your shell.

like image 5
fuzzy-waffle Avatar answered Oct 06 '22 10:10

fuzzy-waffle


Well java has serialization and it comes somewhere near to it. Though you can't do it to the lowest level like CPU registers memory address etc since this will require os to be in same state that was when you 'paused' the process.

This can be a good project as a linux kernel module :-)

like image 2
Xolve Avatar answered Oct 06 '22 10:10

Xolve