필터 지우기
필터 지우기

Close my terminal but keep matlab running on a remote Ubuntu

조회 수: 65 (최근 30일)
Nick Tsui
Nick Tsui 2012년 3월 4일
댓글: David Sterling 2022년 8월 23일
hi Folks:
I don't have much experience running Matlab remotely, so please forgive me if you think my question is dumb.
I am running Matlab on a remote Ubuntu from my laptop. My Matlab program takes hours, or even days to run. So the best way is to let it run on the remote Ubuntu even if I logout my connection with it.
I was told screen command can do that. So here is what I did:
1. Connect to the remote Ubuntu using butty, initiate a new screen session, and start Matlab.
2. Let the Matlab scrip run. (when Matlab script is running, its interface is shown on my laptop)
3. Detach, and then logout the screen session.
4. Close butty (of course, the Matlab windows on my laptop were also gone)
5. Reconnect to the remote Ubuntu, and re-attach the screen session.
But, no Matlab was running!
So, how do I run my Matlab script on that remote Ubuntu with my connection to that server is closed?
Thanks a lot. Any suggestion is appreciated.

채택된 답변

Jason Ross
Jason Ross 2012년 3월 5일
I think when you log out of the screen session, you are killing MATLAB. Here's a worked example:
% screen -ls
No Sockets found in /var/run/screen/S-myusername.
% screen
% screen -ls
There is a screen on:
24084.pts-1.hostname (03/05/12 13:39:28)
(Attached)
1 Socket in /var/run/screen/S-myusername.
% matlab
Now I detach (control-a control-d). I can verify that MATLAB is still running with "ps". I exit from the terminal, then establish a new connection.
% screen -ls
There is a screen on:
24084.pts-1.myhostname (03/05/12 13:39:28)
(Detached)
% screen -r 24084.pts-1.myhostname
Now I'm back in MATLAB.
  댓글 수: 3
Martin Pecka
Martin Pecka 2016년 10월 7일
This, however, seems not to work if you ssh to the machine with X11 forwarding (ssh -XY ...). In my experience, Matlab crashes when you attach to the screen session after a detach-and-disconnect. It's interesting it doesn't die as soon as you disconnect, but only after reconnection.
Rub Ron
Rub Ron 2020년 6월 8일
Could you please explain how to answer the OP question with that code?

댓글을 달려면 로그인하십시오.

추가 답변 (5개)

Daniel Shub
Daniel Shub 2012년 3월 5일
I use screen. I am pretty sure this is exactly what it was designed for.

Honglei Chen
Honglei Chen 2012년 3월 5일
I normally use VNC for such purpose. I started a VNC server on the remote machine and then connect to it using a VNC client. Once I'm done starting the program, I just close the VNC client. I connect again later to check the results.

Nick Tsui
Nick Tsui 2012년 3월 5일
OK, here is how I dealt with it.
I changed the matlab code, such that no figures will pop up. Then I connected to the remote Ubuntu. Then I quit X11 forwarding. Then I initiated a new screen session. Then I started matlab from console, putty terminal. Then I ran matlab script. Then I detached the screen session. Then I logout.
I think it worked. Thanks everybody.
Just no figures, save your data somewhere, you can reload it and re-plot later on.
  댓글 수: 2
Jason Ross
Jason Ross 2012년 3월 5일
FWIW, if you used the VNC method you could have the figures back.
Robin tournemenne
Robin tournemenne 2018년 2월 27일
On high performance computing platforms you usually don't have the rights to use VNC but only ssh.

댓글을 달려면 로그인하십시오.


PureLearningCoding
PureLearningCoding 2017년 4월 4일
I am using tmux and had similar problem. If I stop the X-ming server, the problem is gone.

Subhradip Paul
Subhradip Paul 2020년 5월 13일
you can use:
nohup matlab -nosplash -nodisplay -nodesktop -r 'try; scriptname without .m; catch; save code_err; end; quit'>output.log &
you have to save the workspace though at the end of the script.
Also if there is an error, it will save data till there on code_err
you can check the output on output.log using less or vim.
  댓글 수: 4
mathieu perton
mathieu perton 2021년 3월 18일
It is wonderful ! Thanks a lot.
David Sterling
David Sterling 2022년 8월 23일
As mentioned above, If you are using tmux (presumably something simillar happens with screen), you can run matlab interactively in the terminal with :
matlab -nodisplay -nodesktop
You can then disconnect from your tmux session (whether on purpose or because you connection to the remote machine drops) ; when you re-attach to your tmux session in the future Matlab (and any other processes running in that session) will still be running.
I use this method to keep my Matlab sessions alive on a remote machine running Ubuntu 20.04 -- works great

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by