home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 1.26 What a Multiuser System Can Do for You Chapter 1
Introduction
Next: 1.28 Some Gotchas with Background Processing
 

1.27 How Background Processing Works

Remember that the shell sits there listening to what you type, and calling other programs to do jobs that it doesn't have built-in commands to do.

Normally, when the shell calls another program, it waits for the other program to finish. All the ampersand ( & ) at the end of a command line does is tell the shell not to wait.

Both the Bourne shell and the C shell allow background processing. But, on UNIX systems that have job control ( 12.1 ) , the C shell, bash and ksh give you a lot of extra capabilities for manipulating background processes.

Here's the tip of the iceberg:

  • If you forget to put a job into the background, you can stop it on the fly with a suspend signal ( 38.1 ) by typing CTRL-z. Then use the bg command to put it into the background and restart it:

    % 
    
    find /usr -name tim -print > mine
    
    
    
    [CTRL-z]
    
    Stopped
    % 
    
    bg
    
    
    [1]    find /usr -name tim -print > mine &

  • You can bring the current background job ( 12.3 ) into the foreground with the fg command. This is handy when UNIX stops the background job that needs input from your keyboard (you can't type to jobs running in the background).

  • If you have a lot of background processes running, you can use the jobs command to list them all, and then bring a selected job into the foreground by job number. You can also kill jobs by job number rather than by process ID.

- TOR


Previous: 1.26 What a Multiuser System Can Do for You UNIX Power Tools Next: 1.28 Some Gotchas with Background Processing
1.26 What a Multiuser System Can Do for You Book Index 1.28 Some Gotchas with Background Processing

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System