session the whole time the job is running. Say that you mean to run it with an
& at the end so that it will run in the background, but you forget. No worries.
You can press Ctrl+Z to suspend the job and then you type this:
Click here to view code image
matthew@seymour:~$ bg
That’s it. This causes the process to resume but this time running in the
background.
Both bg and fg, if entered with no further arguments, operate on the job you
have most recently interacted with.
Remember that the jobs command lists all current jobs and their status
(running, stopped, and so on). If you want to move a job running in the
background to the foreground, first list the running jobs. Each one has a
number next to it in the listing. Use the job number to move a job to the
foreground, like this:
Click here to view code image
matthew@seymour:~$ fg %2
If you want to move a specific job to the background, just add the job number
the same way:
Click here to view code image
matthew@seymour:~$ bg %2
Remember that jobs running in this manner terminate when the shell is
closed. If you want a job to continue after you exit, you should consider using
a tool such as byobu, covered later in this chapter, or learn to run the process
as a daemon, which is beyond the scope of this chapter and requires you to do
some further research.
Printing Resource Usage with top
The top command is unusual in this list because the few parameters it takes
are rarely, if ever, used. Instead, it has a number of commands you can use
while it is running to customize the information it shows you. To get the most
from these instructions, open two terminal windows. In the first one, run the
program yes and leave it running; in the second one, run top.
When you run top, you see a display like the one shown in Figure 12.1.