How to move jobs to the background in the Linux system?

LinuxOperating SystemOpen Source

TCP/IP Socket Programming HandsOn-Windows & Linux in C & C++

29 Lectures 9 hours

To move foreground jobs in the background, we use the bg command in the Linux system.

bg (background) – The bg command is used to move foreground jobs in the background. It resumes execution of a suspended process in the background. If no job is specified, then the bg command work upon the currently running process.

Syntax

The general syntax of the bg command is as follows −

bg [job_spec ...]

Job Identifiers −

Sr.No.Notation & Meaning
1%n
Job number
2(n)%string
Refer to a job which was started by a command beginning with string
3%? string
Refer to a job which was started by a command containing string
4%% or %+
Current job
5%-
Previous job

Exit status for the bg command −

The bg command returns success unless job control is not enabled or an error occurs.

To move the current job into the background in the Linux system using the terminal, we use the bg command.

First, we need to create a job in the Linux system.

$sleep 200 To move the previous job into the background in the Linux system using the terminal, we use the bg command with %- job identifier as shown below. $ bg %-

To move the job into the background by specifying job id, we use the below command as follows.

$bg %<job id> To move the job into the background by specifying job name, we use the below command as follows. $ bg %<job name>


To check more information about the bg command, we use the --help option with the bg command. It prompts a short note about the bg command as shown below.

\$ bg --help
Updated on 01-Jul-2021 14:50:52