Background Processes and the jobs Command

If your code takes a long time to run after execution, you may consider running it in the background. Consider the executable “test”, I run it as follows

1. Running Processes in the Background

michael@michael-laptop:~$ ./test

while it is running, you do much with the terminal. You can abort it with CTRL + C or you can pause it with CTRL + Z

michael@michael-laptop:~$ ./test
^Z
[1]+  Stopped                 ./test

The last line is exactly what you would get if you typed the job command. You can now send this process to run in the background by typing bg

michael@michael-laptop:~$ bg
[1]+ ./test &
michael@michael-laptop:~$ 

Typing jobs again will now show you that the process is running in the background

michael@michael-laptop:~$ jobs
[1]+  Running                 ./test &
michael@michael-laptop:~$

When the process finished, a confirmation will be displayed in the terminal like this

[1]+  Done                    ./test
michael@michael-laptop:~$ 

In addition, you can bring processes back to the foreground by entering fg
job_id
, where the job id is found from the jobs command (it is the number before the process e.g. 1 in this example).

You may now also wish to know how to kill background processes