Please forgive the cross-post from matlab answers. This received no response over there. I'll try to go into a bit more detail with this post.


I run matlab through emacs using matlab-emacs. I do this on a subnode of a cluster computer. I have no problems running emacs with the following set of commands, from my laptop computer.

 ssh host1
 ssh node005

and then in emacs I run matlab-shell and matlab runs untill I disconnect my laptop. I would like, however, to be able to disconnect my laptop that I use to run matlab and leave a job running. My non successful attempt has so far been to

 ssh host1
 ssh node005
 screen -S sheep

and then in screen I run

 emacs --daemon

and then connect to it with

   emacsclient -nc

I can run matlab within the emacs client (again with matlab-shell). However when I disconnect from the screen session

 ctrl-a d

and then reconnect

 screen -r sheep
 emacsclient -nc

And then look at the matlab shell which was already running, I see that my job has teminated and the message

M-Shell exited abnormally with code 1

Why does matlab crash when I detach this screen session? How does it even know I have detached? Alternatively, perhaps there is a better way I can run matlab in the background (besides vnc, which I am using now but has its own set of bugs). Please let me know if I can provide any other information that might help.

Note that this post follows emacsclient connection refused and I am running things as I am essentially in response to that earlier discussion.

edit: there is a description of this set-up allegedly working for someone here: http://sourceforge.net/p/matlab-emacs/mailman/message/31704641/

1 Answer 1


I found your question because I want to do the same thing (resume a screen session without Matlab crashing), but I have not found a way to do it. Instead, I run a nohup job (this is in tcsh):

nohup nice matlab -nodisplay -nojvm < list_of_matlab_calls.m >! /dev/null &

You can replace /dev/null with a log file if you wish. I use head so that the log file doesn't become huge if an error message keeps getting written.

nohup nice matlab -nodisplay -nojvm < list_of_matlab_calls.m | head -c1M >> log_file.txt & 

I would rather use screen if possible, so please let us know if you find a way to do it.

Edit: actually it seems I can use Matlab within screen if I start Matlab with a nohup (can log out, log in, and resume screen session). I thought I had tried this before and gotten an error.

  • Neat! What exactly do you run after attaching to screen to run matlab? Neither nohup matlab & nornohup matlab < /dev/null &>/dev/null give me a working matlab interface. Am I missing something?
    – ohnoplus
    Oct 7, 2015 at 22:34
  • Sorry, that was unclear. The lines I quoted are run from the command prompt, without the Matlab interface. To run a Matlab session in screen, I start screen, and at the command prompt run: nohup nice matlab -nojvm -nosplash The nice is because I am running hours/days-long jobs and want to allow other users' jobs priority. Using this command, I am able to detach my screen and logout without Matlab quitting.
    – oddwing
    Oct 9, 2015 at 0:09
  • Thanks for all of this. So this works for running matlab without any interactive display, outside of the emacs client I presume. I still haven't had any luck reconnecting to an interactive matlab session.
    – ohnoplus
    Nov 11, 2015 at 19:22
  • I should note that I am using tcsh, and nohup may differ depending on your shell.
    – oddwing
    Nov 18, 2015 at 20:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .