Discussion:
Saving program state in executable
(too old to reply)
Peter Brooks
2007-06-16 20:33:55 UTC
Permalink
I imagine that this is probably platform dependent. What I'd like to
do, though, is to run a program and save its state, so that, when it
is run again, it starts where it left off, even if the machine has
been re-booted between times.

That is, I'd like the executable file (un*x) or .exe file (msdros) to
be saved each time it runs so the program retains its state.

Is there a platform independent way of doing this? Or, maybe more
sensibly, are there equivalent ways of doing this in various systems
that can be set with compile switches?
CBFalconer
2007-06-17 00:18:03 UTC
Permalink
Post by Peter Brooks
I imagine that this is probably platform dependent. What I'd like
to do, though, is to run a program and save its state, so that,
when it is run again, it starts where it left off, even if the
machine has been re-booted between times.
That is, I'd like the executable file (un*x) or .exe file (msdros)
to be saved each time it runs so the program retains its state.
Is there a platform independent way of doing this? Or, maybe more
sensibly, are there equivalent ways of doing this in various
systems that can be set with compile switches?
Won't work. The program state normally depends on the data, not
the code.
--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net
--
Posted via a free Usenet account from http://www.teranews.com
Peter Brooks
2007-06-17 03:58:03 UTC
Permalink
Post by CBFalconer
Won't work. The program state normally depends on the data, not
the code.
What I'm wanting to do has been referred previously to as save-restart
state code.

You can do it manually by saving all data, then re-loading it. Since
this saves the data in internal structures, this might be quicker than
loading the XML stuff raw.

However, what I'd really like is a couple of general purpose functions
that do save_heap_stack(fp) and restore_heap_stack(fp) - that would
enable the entire current heap and stack to be stored to a file, then
restored. Then all I'd need to do on running hte program is to check
if there's a previous state, if there is, simply restore it.

That's what I'm looking for.
CBFalconer
2007-06-17 13:37:47 UTC
Permalink
Post by Peter Brooks
Post by CBFalconer
Won't work. The program state normally depends on the data, not
the code.
What I'm wanting to do has been referred previously to as save-restart
state code.
You can do it manually by saving all data, then re-loading it. Since
this saves the data in internal structures, this might be quicker than
loading the XML stuff raw.
However, what I'd really like is a couple of general purpose functions
that do save_heap_stack(fp) and restore_heap_stack(fp) - that would
enable the entire current heap and stack to be stored to a file, then
restored. Then all I'd need to do on running hte program is to check
if there's a previous state, if there is, simply restore it.
That's what I'm looking for.
Won't work. For example, there is no guarantee that heap addresses
that were used before are still available.
--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net
--
Posted via a free Usenet account from http://www.teranews.com
Marco van de Voort
2007-06-17 16:57:50 UTC
Permalink
["Followup-To:" header set to comp.lang.pascal.misc.]
Post by CBFalconer
Post by Peter Brooks
that do save_heap_stack(fp) and restore_heap_stack(fp) - that would
enable the entire current heap and stack to be stored to a file, then
restored. Then all I'd need to do on running hte program is to check
if there's a previous state, if there is, simply restore it.
That's what I'm looking for.
Won't work. For example, there is no guarantee that heap addresses
that were used before are still available.
For most protected mode systems it does. Specially if the running scope is
one system.

However I don't know any non embedded systems that allow this, so the point
is moot.

Marco van de Voort
2007-06-17 10:57:22 UTC
Permalink
Post by Peter Brooks
I imagine that this is probably platform dependent. What I'd like to
do, though, is to run a program and save its state, so that, when it
is run again, it starts where it left off, even if the machine has
been re-booted between times.
Then you would have to freeze the entire program and kernel. Which is
awfully hard. (also part of the kernel state, since at the moment of
freezing the program could be communicating with the kernel, though probably
some very small limitations could solve that).

The classic solution under Unix is a core dump of a process. (a dump of the
memory). IIRC EMacs distribution used to be based on it. (startup, then
coredump, and then always start the coredump, saving the LISP startup
overhead).
Post by Peter Brooks
Is there a platform independent way of doing this? Or, maybe more
sensibly, are there equivalent ways of doing this in various systems
that can be set with compile switches?
No. This is kernel stuff, so you will probably need a way to tell the kernel
to dump/reload a process from/to a dump. But this is an black art, not
something simple.
Continue reading on narkive:
Loading...