# Is it possible to save an interrupted computation?

I've got this really time consuming factoring problem. To decouple things a bit, I decided to start Mathematica using the command line interface (under screen).

\$ math


So my code is running, and I know that I can interrupt it with Ctrl-C, but what I want to do is interrupt it, and then write the state of the process to disk, so that I can reboot. On Linux, there is a program called CryoPID which might work. Unfortunately, my computation is running on OS X.

I can detach from the screen session and re-attach to it, but if I reboot the machine I know it'll lose memory and the computation progress so far. My question is: can you save the state of a Mathematica computation that you interrupt (to disk and reloadable after a restart). Thanks.

-

When you press Ctrl-C, you get a prompt. If you type i at this prompt, you'll enter a "dialogue" with Mathematica. You can examine the internal state, look at the values of all the variables, look at Stack[], etc. Evaluating Return[] will resume the computation. (Warning: Ctrl-D or Quit will still quit.)
If your computation is not too complicated, you may be able to extract enough information so you can resume later. But the chances that this will work in practice are not great. For example you can't extract a partial result from Table because it's not stored in a user-accessible variable.