Posts Tagged ‘background’

Send a process to the background and the foreground

Sunday, March 23rd, 2008

To run a process in the background, simply append a space and an ampersand (&) at the end of the commandline. At any time, you can then run the ‘jobs’ command. This shows you what processes have been run in the background. They are listed numerically. When you are ready to resume a process in the foreground, you type in ‘fg %[INSERT PROCESS NUMBER HERE]‘. You get the process number from the ‘jobs’ command we ran before.

As an example, let’s try this with top. First, we run it in the background:

[1100][tux@training:~]$ top &

[1] 11746

[1100][tux@training:~]$

Next, let’s take a look at the jobs we have running in the background:

[1100][tux@training:~]$ jobs

[1]+ Stopped top

[1102][tux@training:~]$

We can see that top has a [1] in front of it. We are going to use the ‘1′ to bring that job back to the foreground:

[1102][tux@training:~]$ fg %1

You will then see the output of top as you normally would expect.