Job Control

General Information

Sometimes processes can take time to complete, thus tying up your console session. Adidas Gazelle Soldes asics whizzer What if you want to run multiple processes in the background on the same shell session? With the built-in job control, you can. adidas zx flux belgique new balance femme avis bottes ugg chaussures timberland Adidas soldes There are three main conditions a job can be in: Running, Stopped/Suspended, or Terminated. ugg noir nike air max 1 asics gel lyte 3 soldes timberland To control them, we’ll use the fg and bg commands.


Requirements

  1. A SSH client such as puTTy or SecureCRT (if you aren’t on the box).

Usage

If there is a process that you know will take a while to complete and would like it to be forked to the background immediately, you can append a & at the end of the command to achieve this. timberland soldes ugg soldes new balance 574 ugg pas cher For this example, we’ll just create a simple timer.

 $ sleep 100 & [1] 45862 $ 

As you can see the command prompt was returned after displaying two important numbers. nike air max 90 femme 2017 new balance avis The first number [1] is the job number which is used by other job control commands to reference it. adidas superstar soldes nike pas cher 2017 ugg classic mini The second number 45862 is the process ID that the system assigns. ugg boots pas cher asics aaron So, the job number is unique to the shell and the process ID is unique to the operating system. nike x fragment air jordan en soldes If you forget what job number you want to reference, you can always see a list of all the jobs in the job controller:

 $ jobs [1]+ Running sleep 100 & $ 

Here you can see that the original job is in the Running state. nike air max 90 asics gel lyte 3 soldes Now, if you want to bring it to the foreground, you can use the fg command:

 $ fg 1 sleep 100 

Now, if you have a job running in the foreground and you want to send it to the background, you can hit control-z to suspend or stop the job. bottes ugg This will return the command prompt.

 $ fg 1 sleep 100 ^Z [1]+ Stopped sleep 100 $ 

You can now continue the job in the background with the bg command:

 $ bg 1 [1]+ sleep 100 & $ 

So, now you have a job running in the background and you want to kill it. Chaussures adidas running new balance new balance Well, you can either bring it to the foreground and interrupt it with control-c, kill the process ID, or kill the job number. nike air huarache pas cher nike air max 1 Here I’m going to kill the process using the job number:

 $ kill %1 [1]+ Terminated: 15 sleep 100 $ 

Now you can see the job is terminated.

Note: When jobs are running in the background, they may still send their output to the terminal.

Speak Your Mind

*