next up previous contents
Next: Priority (nice) Up: The Shell (csh, tcsh, Previous: Batch jobs and Calendar   Contents

Background jobs (&)

To save your time, run commands in the background. When commands are running in the background you can continue to run other commands as usual, that is, in the foreground.

Use the ampersand character, &, at the end of a command line to start the command in the background. E.g.:

malama% spell letters > letters.err &
[1] 69
malama%

The computer will give you the job number and a new prompt so you can continue with a new command. The system will type a message that the job is done when it has finished executing the background job and you have asked it to perform another command. It will not interrupt your editing session or any other program with the message in the middle of the screen. If your program expects input from the terminal, you can put the necessary commands in a file and redirect that as standard input using the < character. For example,

malama% myprog < indata > outdata &
[2] 71
malama%

That way it will not stop and wait for you to foreground it and type the input. Note that you can redirect both input and output in the same command, as shown above.

Be careful to redirect both ``standard output'' and ``standard error'' to a file if you intend to log off before the job finishes; otherwise, whoever logs in after you on the same terminal (or pseudo-terminal, which is used when coming in with rlogin or from MAX) will get all your screen messages, which can make it very difficult to do anything. The syntax for doing this is quite different in the various shells. For the C-shells, it is very simple: simply add another ampersand (&) immediately following the >.

malama% myprog < indata >& outdata &

Look in the ``SUNOS User's Guide: Getting Started'' manual for more information, or see the man page on your shell.


next up previous contents
Next: Priority (nice) Up: The Shell (csh, tcsh, Previous: Batch jobs and Calendar   Contents
h.stilmack@jach.hawaii.edu