Re: prolonged number crunching
On Thu, 2001-12-06 at 20:21, Alec wrote:
> I have a program that produces output to STDOUT and will probably take
> several days to run. I already figured that it's better to run it using "at"
> utility and collect the results by email. This way the program will not be
> bound to any specific terminal and, say crashing X, will not interrupt it.
> I'm wondering if there's also a way to insure against shutting down of the
> machine, i.e. enable saving of the session (RAM) at shutdown and restarting
> from where it stopped when the computer is brought up?
At shutdown, your program will receive a signal, SIGTERM, delivered by
init. A little while later, if your process is still running, it will
receive SIGKILL. You can handle the former but not the latter. If your
process can clean up and save state within a few seconds, I suggest
adding a signal handler to deal with SIGTERM. This way your program can
pick up where it left off when you restart it.
There is not a generic way to freeze and thaw arbitrary processes under
Linux. This would be a very spiffy feature but I don't think anyone is
working on it. Conceivably you could just write out all the processes
pages, save its kernel context, stack, and stack pointer, and restart
the process later. Unfortunately you then also have to deal with
process relationships (parent/child, process groups), ownership and
priviledges, file handles, and timers. I don't think it's going to
happen any time soon.