sh Job Control Pause, run in background, run in foreground


Example

Let's create a process which is rather long to complete :

$ sleep 1000

To pause the process, type Ctrl + Z :

^Z
[1]+  Stopped                 sleep 1000

You can use jobs to see the list of processes running or stopped in the current terminal :

$ jobs
[1]+  Stopped                 sleep 1000

To bring back a job on the foreground, use fg with the id written between brackets in the list provided by jobs :

$ fg 1                                                     
sleep 1000

When a job is stopped, you can run it in background with the command bg with the same id :

$ bg 1                                                     
[1]+ sleep 1000 &

And then see it in the list of jobs in the current terminal :

$ jobs                                                     
[1]+  Running                 sleep 1000 &

To directly run a job in background, finish the command with & :

$ jobs                                                     
[1]+  Running                 sleep 1000 &                                      
$ sleep 5000 &
[2] 6743                                                                        
$ jobs                                                     
[1]-  Running                 sleep 1000 &                                      
[2]+  Running                 sleep 5000 &