In interactive mode (in Octave, gnuplot, R, etc.) I occasionally press Control + z by mistake. This pauses the program and kicks me back to the terminal.

Is it possible to re-enter the original interactive mode (with all the stored variables)?

To reproduce:

~> octave
octave:1> a = [1:10];
octave:2> ^Z
[1]+  Stopped                 octave

How can I recover my session with the variable a defined?

4 Answers 4


type fg and hit enter in terminal.

   fg [jobspec]
          Resume jobspec in the foreground, and make
          it  the  current  job.   If jobspec is not
          present, the shell’s notion of the current
          job  is used.  The return value is that of
          the command placed into the foreground, or
          failure  if  run  when job control is dis-
          abled  or,  when  run  with  job   control
          enabled,  if  jobspec  does  not specify a
          valid job or jobspec specifies a job  that
          was started without job control.

Type the following to pull the job to the foreground again:


This is because you suspended the job, meaning it's doing nothing while you can't see it. You can actually let a job run in the background too (by entering bg). See Job Control for more info.


You can use fg to bring the foreground activity back


You can use bg to move the current activity to background.


In linux you could use reptyr PID_number.

If for example you had been running vim in your terminal then
first get the terminal PID_number with something like
ps -ax | grep vim

sudo reptyr PID_number

Scroll through open applications and you should see your terminal as it was.


  • zsh: command not found: reptyr Not installed by default on all OSes.
    – jnovack
    Sep 25, 2020 at 20:24
  • Yes, this package you will have to install, but it works
    – Kes
    Oct 15, 2020 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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