ÅÝܽ¶ÌÊÓƵ

print friendly version

Questions and answers

936
Is it possible to run background or batch processes in Matlab for Unix?


Yes it is possible. The website indicates the following for Windows and Unix:


To run MATLAB in the background, you need to do the following:

1. redirect the standard input
2. redirect the standard output
3. eliminate the graphical output
4. call MATLAB as a background process

You may also want to change the process's priority to decrease its effect on total CPU usage.

Here is a simple script written for the UNIX C shell, which demonstrates one way of running MATLAB in the background:

#!/bin/csh -f
# Clear the DISPLAY.
unsetenv DISPLAY # unset DISPLAY for some shells
# Call MATLAB with the appropriate input and output,
# make it immune to hangups and quits using ''nohup'',
# and run it in the background.
nohup matlab < $1 > $2 &

 

Save this script in a file called matbg and change its permissions to make it executable. The syntax for calling it is:

  • matbg where is the M-file to be executed, and is the file to which the output will be sent.

If you are not interested in saving the output, you can specify /dev/null as the second argument. If you want to change the process's priority, you can use the UNIX command nice in the line, which invokes MATLAB. For example, if you wish to change MATLAB's priority to 10, change the appropriate line to the following

  • nohup nice -10 matlab < $1 > $2 &

Help us to improve this answer

Please suggest an improvement
(login needed, link opens in new window)

Your views are welcome and will help other readers of this page.

Categories

This is question number 936, which appears in the following categories:

Created by Jason Bailey on 15 March 2002 and last updated by Mark Wilson on 8 August 2016