The background processes in Linux refer to the processes running in the background for a particular session which foreground processes are the ones which are currently being operated upon. The commands to manage the processes are as follows:

Show background jobs:

Use ‘bg’ command to display all the processes which are running in the background.

Sending the job to background:

Use ‘CTRL+Z’ for it.

# find / -ctime -1 > /tmp/changed-file-list.txt

# [CTRL-Z]
[2]+  Stopped                 find / -ctime -1 > /tmp/changed-file-list.txt

# bg

Bringing the job to foreground:

Use ‘fg’ command to bring the background job to foreground. You can use the job number to bring the desired job.

Display the current jobs:

Use ‘jobs’ command to display the jobs running in current session.

# jobs
[1]   Running                 bash &
[2]-  Running                 evolution &
[3]+  Done                    nautilus .

Kill a background job:

Use ‘kill’ command for this purpose. Use it with %job_number to kill the desired job. For example, if we want to kill the job # 2, we will use the following command.

# kill %2

What happens to the jobs when I close my session?

Well, the jobs are washed away by hup process of Linux when you close the session. What if I want to keep the jobs running even if I log out? In this case, we use the command nohup which ignores the hup signal in Linux and keeps the process running.

Adnan Khurshid

Adnan Khurshid, the author of this article, has been working in a telecommunication sector since 2007. He has worked there as a VAS (Value Added Services) engineer and has excelled remarkably in the field. Working in this field has been his passion and he has always made efforts to keep himself up to date. Find more about him on LinkedIn

More Posts

Tags: , , , , , ,

Leave a Reply