# 1.1 Running MATLAB in the Background Under UNIX

## Problem

When running time-consuming M-files, it may be desirable to run MATLAB in the background in order to work on something else or to log out of the computer.

## Solution

When running MATLAB in the background, you need to consider the following issues:

- redirecting the standard input
- redirecting the standard output
- eliminating the graphical output
- calling MATLAB as a background process

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

Here is a simple script written for the UNIX C-shell:

    #!/bin/csh
    # Save the DISPLAY setting and clear it.
    set OLDDISPLAY=$DISPLAY
    unsetenv DISPLAY
    # Call MATLAB with the appropriate input and output and make it
    # immune
    # to hangups and quits using ''nohup''. Make it run in the
    # background.
    nohup matlab < filein > fileout &
    # Reset the DISPLAY setting
    setenv DISPLAY $OLDDISPLAY

In this script filein represents the M-file to be run and fileout represents the file to which the standard output is sent. If you want to change the process' priority, you may 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 < filein > fileout &

(c) Copyright 1994 by The MathWorks, Inc.