Close the terminal but keep matlab running remotely

17 views (last 30 days)
Hi, I have to run some programs remotely in a cluster.
The problem is the following, the programs run for two or three days (they are really heavy). I connect to the cluster and run the programs with the following command
matlab -nosplash -nodesktop -r script
the program runs properly, but if I close the terminal the program stops running, and if I disconnect from the network the program give me the following error: "broken pipe".
Is any way that I can run the program and I can disconnect or close the terminal and the program keep running?
Thank you very much

Accepted Answer

Walter Roberson
Walter Roberson on 13 Aug 2013

Investigate using "screen" or "vnc", if you want to be able to reconnect to the session.

If you want to be able to run the script "in batch", not needing to interact with it after it starts, then if it is a Unix-type system, consider using the system "batch" command, or else use

nohup matlab -nosplash -nodesktop -r "try; script; catch; end" < /dev/null > /dev/null 2> /dev/null

(bourne or ksh derivatives, might need a slightly different syntax on csh)

  5 Comments
Iván
Iván on 14 Aug 2013

Thank you very much for your answers Walter. I finally find the following code that worked for me:

unsetenv DISPLAY
nohup matlab -r mybgprocess -nodisplay -nosplash -nojvm -nodesktop > & ! matlab.out < mystdio.txt &

The file 'mybgprocess.m' contains the MATLAB commands that you want to run. It is important that this function has a QUIT or EXIT statement at the end so that the MATLAB process is closed after you script is done executing. The file 'mystdio.txt' can be an empty file, but it needs to exist. Without this file, the standard input of the MATLAB process would be empty, which would cause the MATLAB process to die. The file 'matlab.out' will store the output of the MATLAB Command Window to your commands.

Source:

http://www.mathworks.com/support/solutions/en/data/1-5P0HFE/?solution=1-5P0HFE

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!