O'Reilly logo

Learning the UNIX Operating System, Fourth Edition by Jerry Peek, John Strang, Grace Todino

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 6. Multitasking

Suppose you are running a command that will take a long time to process. On a single-task system like MS-DOS, you would enter the command and wait for the system prompt to return, telling you that you could enter a new command. In UNIX, however, there is a way to enter new commands in the “foreground” while one or more commands are still running in the “background.” This is called background processing.

When you enter a command as a background process, the shell prompt reappears immediately so that you can enter a new command. The original command will still be running in the background, but you can use the system to do other things during that time. Depending on your system and your shell, you may even be able to log off and let the background process run to completion.

Running a Command in the Background

Running a command as a background process is most often done to free a terminal when you know the command will take a long time to run.

To run a command in the background, add the “&” character at the end of the command line before you press the RETURN key. The shell will then assign and display a process ID number for the command:

% nroff -ms chap1 > chap1.out &
[1] 29890
%

(The nroff program formats documents. It’s a good example because text formatting usually takes a while, so users often do it in the background. See your UNIX documentation for details on nroff.)

The process ID (PID) for this command is 29890. The PID is useful when you want ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required