Running Commands in the Background

team bbl


Some commands take a long time to finish executing. For instance, the following command stores the name of every file on your computer in the file allfiles:

 ls -lR / > allfiles 

This command can tie up your command line for a long time until it completes the job. If you don't want to wait for a command to finish, you can execute the job in the background, allowing you to enter other commands while your first command is executing. You can start the command in the background by adding an ampersand (&) to the end of the command, as follows:

 ls -lR / & 

A number is assigned to background jobs in consecutive order. The job number displays when the command is submitted and used to monitor the status of the background job.

You can also send a job that is already running to the background, as follows:

 Ctrl-z bg 

The first line suspends the job. The second line starts the job in the background.

You can list the jobs that are running by typing:

 jobs 1 ls lR / 

You can bring any job into the foreground with the command:

 fg jobnumber  

For example:

 fg 1 

    team bbl



    Spring Into Linux
    Spring Into Linux
    ISBN: 0131853546
    EAN: 2147483647
    Year: 2005
    Pages: 362
    Authors: Janet Valade

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net