Background Tasks

TODO — I seem to have neglected to finish this page

By default, when you enter a command at the command prompt — which, you will remember, is simply an instruction for Linux to execute a particular application — the command prompt won't return control until the program finishes. If you're at the command prompt, and decide that you want to watch a movie, you can use the totem command, like this:

$ totem

However, if you do, you won't be able to enter any more commands until totem finishes running. But what if you want to continue entering commands at the command line, while your movie plays in the background? You can do so by entering a & character, after the command (and any related parameters). If you enter

$ totem &
[1] 7768
$

it will start totem, but it will then give you some cryptic numbers, and put you right back at the command prompt. The totem application will also open — probably on top of your terminal window — and will continue to run until you close it, regardless of anything you do in the terminal window. As far as the BASH shell is concerned, the job is running in the background.

Those numbers that showed up on the screen are the job ID of the task which is running in the background. If you want to see a list of all of the background tasks which are running, you can use the jobs command:

$ jobs
[1]-  Running                 totem &
[2]+  Running                 gedit &
$

If you close any of the applications that are running in the background, and execute the jobs command again, the job will disappear from the list.

And it's not just GUI programs that you can run in the background; you can run any long-running task in the background. If you ever wish to bring one of those tasks back to the foreground, you can use the fg command.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.