Introduction to Data Communications | ||
---|---|---|
Previous | 51d. Background Processing | Next |
Job Control is used to manage multiple processes and allows users to manipulate foreground and background processes.
To run a process in the background, add "&" to the end of the normal command:
sleep 120&
In the above example, the sleep command causes the UNIX terminal to do nothing for 120 seconds. The "&" indicates that it is performed in a background process.
Moving a Foreground Process into the Background
In order for a foreground process to be moved into the background, it first must be running in the foreground. Then the foreground process must be stopped using "ctrl z" which is the pause command. Once stopped, the bg (background) command can be used to start the process running again.
Example:
pr index.txt (prints the file index.txt to standard output) ctrl z (stops process - pauses) stopped (Unix replies with "stopped" message) bg (instructs process to move to the background) [1] pr index.txt (displays process moved to background)
To display currently running jobs, type:
jobs [1] RUNNING pr index.txt
Moving a Background Job to the Foreground
To move a background job or process to the foreground, you must know the job number. The number in square brackets [ ] indicates the job number.
jobs [1] RUNNING pr index.txt
To move the background job to the foreground, use the fg (foreground) command:
fg OR fg1 OR fg %1 (1 indicates job number)
This will move job #1 to the foreground. The fg command will be implemented just a little bit different depending on the shell or flavour of Unix run.
Introduction to Data Communications | ||
---|---|---|
Previous | Table of Contents | Next |