3.11.2 Foreground and background

Rate this post

Next: 3.11.3 Backgrounding and killing Up: 3.11 Job Control Previous: 3.11.1 Jobs and processes

            Jobs can either be in the foreground or in the background. There can only be one job in the foreground at any one time. The foreground job is the job which you interact with—it receives input from the keyboard and sends output to your screen. (Unless, of course, you have redirected input or output, as described in Section 3.8). On the other hand, jobs in the background do not receive input from the terminal—in general, they run along quietly without need for interaction.

Some jobs take a long time to finish, and don’t do anything interesting while they are running. Compiling programs is one such job, as is compressing a large file. There’s no reason why you should sit around being bored while these jobs complete their tasks; you can just run them in the background. While the jobs are running in the background, you are free to run other programs.

  Jobs may also be suspended. A suspended job is a job that is not currently running, but is temporarily stopped. After you suspend a job, you can tell the job to continue, in the foreground or the background as needed. Resuming a suspended job will not change the state of the job in any way—the job will continue to run where it left off.

    Note that suspending a job is not equal to interrupting a job. When you interrupt a running process (by hitting your interrupt key, which is usually ), it kills the process, for good. Once the job is killed, there’s no hope of resuming it; you’ll have to re-run the command. Also note that some programs trap the interrupt, so that hitting won’t immediately kill the job. This is to allow the program to perform any necessary cleanup operations before exiting. In fact, some programs simply don’t allow you to kill them with an interrupt at all.

Lire aussi...  Site Internet de Medasys

Next: 3.11.3 Backgrounding and killing Up: 3.11 Job Control Previous: 3.11.1 Jobs and processes

Matt Welsh