0

Is there a way in C/C++ to copy an entire process' runtime space into a data blob?

Basically I want to be able to suspend a process sort of like what happens when a computer is hibernated. The registers, memory space (stack and heap) are all written to disk and reloaded when the computer starts back up.

Is there anyway to dump a process in C/C++ (why not C# while we're at it) that would allow it to be loaded back up and continue execution (assuming it's a VERY simple program), or would this require running as kernel or low level assembly to accomplish?

TheBat
  • 1,006
  • 7
  • 25
  • Have you tried anything yet or do you just want to be given the answer? – ZoomVirus Oct 08 '14 at 14:23
  • no because the pointers in the process wouldn't be pointing to valid memory locations afterwards – camelccc Oct 08 '14 at 14:23
  • You mean like a [memory dump](http://msdn.microsoft.com/en-us/library/windows/desktop/ms680360(v=vs.85).aspx)? – EdChum Oct 08 '14 at 14:24
  • I haven't tried anything yet, it's more of a curiosity question. I've done a bit of digging on google, and couldn't turn up anything. – TheBat Oct 08 '14 at 14:24
  • @camelccc shouldn't virtual memory alleviate this problem? – TheBat Oct 08 '14 at 14:26
  • Do you know much about signals in c++? – ZoomVirus Oct 08 '14 at 14:28
  • The reason that sleep, hibernate etc. work is that the processes are not unloaded from the OS. Suspending a process in such a manner requires massive OS support, even in a simple case. It would add layers to all I/O operations. To attempt something like this on a process with threads stuck on inter-process comms using shared memory, for example, would be a nightmare to manage. – Martin James Oct 08 '14 at 14:32
  • any linked dll's / libraries won't come back to the same location (they will be a function of the order in which other applications were loaded) . You can't access memory unless it's been newed or malloced, and the os can assign pointers for that at will at run time at will ... I could go on forever. – camelccc Oct 08 '14 at 14:32
  • Taking how games are saving, you can *dump* state (serialize state of everything what is needed) and then *load* it back (deserialize). This will allow you to continue play from where you were last. – Sinatr Oct 08 '14 at 14:33
  • I remember hearing about an old program that would save your settings by having them stored in global variables. It would then overwrite its own executable on shutdown with an image of itself. – sjdowling Oct 08 '14 at 14:34

0 Answers0