I perform long calculations on a fast remote machine running the Mathematica kernel, where I followed the very useful guide Remote Kernel Strategies to establish the connection. I wonder, however, if there is a way to detach the Frontend from the running kernel in the same way as one can use the Linux program screen to keep remote shell sessions alive. I couldn't find anything similar for Mathematica, even though such a feature would be very convenient. Is there a way of doing that?

Many thanks,


  • $\begingroup$ Unfortunately the front end isn’t supporting this in v12 - it may work but many dynamics and other things will most assuredly break, pinking and freezing galore! $\endgroup$
    – M.R.
    Commented Jun 11, 2019 at 4:37
  • $\begingroup$ If you have the option of running remote desktop sessions on the remote machine that would allow you to running the front-end on the remote machine as well, then that would usually preferable. In this case the remote session manager will deal with the process of reconnecting. $\endgroup$
    – TimRias
    Commented Jun 13, 2019 at 9:11

3 Answers 3


This comes a little late, but this is my solution:

Remote Machine running linux with tmux (similar to screen but newer, should work with screen but I dont know the commands) and Mathematica 10 installed.

Local Machine running MacOS Yosemite with Mathematica 10.

  1. Launch tmux in remote machine and execute Mathematica:


    wolfram (executable to mathematica in terminal mode)

  2. Now create a link with TCPIP protocol. Record the linkname="linkPort1@remoteIP,linkPort2@remoteIP" generated.

    link=LinkCreate[LinkProtocol -> "TCPIP"]                                
    LinkObject[linkPort1@remoteIP,linkPort2@remoteIP, 72, 1]
  3. Now in local machine, start Mathematica and go to Evaluation->Kernel Configuration Options -> Add... and fill out the window just as showed below.Dont forget to replace (insert remote ip ) by the remote machine ip address and insertLinkName by the link name that was generated above enter image description here clic ok. Then open a new notebook and set the above created kernel as the notebooks kernel. Dont evaluate anything yet in this notebook.

  4. Go back to your remote machine and run

  5. Finally go back to the notebook in your local machine and evaluate something:


So now you are running the kernel in the remote machine with the front end in your local machine.

  1. To disconnect from the Kernel, evaluate the following in your notebook:

    LinkClose /@ Links[]

At this point your kernel is still running in the remote machine. To reattach follow steps 2 through 5.

This could be automatized with a script. Also if you know that a port is always available, you could set the link with a persisten name so that you dont have to reconfigure the remote kernel each time you attach.

  • 1
    $\begingroup$ Thanks! I just tried what you suggested, using screen on the remote host. It seems to work! Thanks again for stating the solution to this problem in such a clear way! Andreas. $\endgroup$
    – andy269
    Commented Jun 5, 2015 at 19:46
  • $\begingroup$ Sadly this wonderful trick appears to crash Mathematica 12... $\endgroup$
    – Ranza
    Commented Apr 29, 2019 at 17:52
  • $\begingroup$ @Ranza Which operating system does it crash on? $\endgroup$
    – Szabolcs
    Commented Jun 7, 2019 at 8:01
  • $\begingroup$ MacOS Mojave connecting to Linux Remote $\endgroup$
    – Ranza
    Commented Jun 7, 2019 at 9:23
  • $\begingroup$ @Ranza you should email [email protected] with the crash information, so they can investigate and hopefully fix the issue (if you are so inclined) $\endgroup$
    – ktm
    Commented Jun 7, 2019 at 15:42

I have not done this before, but here's how I would approach this:

run the kernel on the remote machine from the command line using the 'background process' approach (i.e. '&' or "start")...

then run a script that will dump out the Mathlink connection id (or equivalent)...pass this to the front-end you want to be the client and start/restart the Mathlink connection...

  • $\begingroup$ Hm, okay, thank you, I might try that. I will report on the outcome later. Andreas. $\endgroup$
    – andy269
    Commented Mar 23, 2015 at 19:44

Again, use tmux to launch the background program. Run



In[1]:= Import["launch.m"]
In[2]:= createLink[]

where launch.m file is the following:

createLink[] :=(link=LinkCreate["1113,51113",LinkProtocol -> "TCPIP"];$ParentLink=link;)
changeFormatType[] :=SetOptions["stdout", FormatType->OutputForm];
detach[] := (LinkClose /@ Links[]; createLink[];)

In Kernel configurations MLopen arguments are

-LinkMode Connect -LinkProtocol TCPIP -LinkHost "<-host->" 
-LinkName "1113@<-host->,51113@<-host->"

and leave the shell command empty.

Now when you run any command on the local machine, it will automatically connect to a remote kernel. Run detach[] to detach from the kernel. When you evaluate any other cell you will be reconnected to the same kernel (with same local variables).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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