Running jobs in the background with bg

If you're running a job that doesn't require input from you, consider running it in the background using bg (Code Listing 9.6). In doing so, you can keep the program running while working on other UNIX activities at the same time.

To run jobs in the background with bg:

1.
jobs

At the shell prompt, type jobs to see the list of all jobs, running or stopped. Note the job numbers on the left.

2.
bg 2

Type bg, followed by the number of the job you want to run in the background (Code Listing 9.6).

Tip

If you want to put the most recently suspended job into the background, just type bg (without the number) at the prompt.


Tip

You can also put jobs directly into the background without first suspending them. Just type the name of the job to run, a space, and & (as in bigdog &). The & moves the job directly into the background.


Code Listing 9.6. Restarting suspended jobs in the background lets you do two things at onceā€”or more. To move a job to the background, just type bg followed by the job number.
[ejr@hobbes ejr]$ jobs
[1]-  Stopped (tty input)
   ftp calvin.raycomm.com
[2]   Stopped (tty input)   telnet
[3]   Stopped (signal)
   lynx http://www.raycomm.com/
[4]+  Stopped                man telnet
[ejr@hobbes ejr]$ bg 1
[1]- ftp calvin.raycomm.com &
[ejr@hobbes ejr]$

Code Listing 9.7. Typing fg plus the job number brings that job into the foreground. When you bring suspended jobs into the foreground, you'll sometimes see the job activities onscreen. At other times, you'll only see a prompt and will need to summon help to see anything of the program.
[ejr@hobbes ejr]$ jobs
[1]+  Stopped                ftp ftp.cdrom.com
[ejr@hobbes ejr]$ fg
ftp ftp.cdrom.com

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.243.32