Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 5 down vote accepted

I doubt that there is a practical way to save the complete internal state and resume the computation where it was interrupted. However, here's what you can do:

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.

For the future, the best thing you could do would be designing the computation to be interruptible by saving partial results into a variable. For something that is already running at this moment, unfortunately the chances are slim.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.