![Forrest logo](/images/logo.png)
bg:tldr:5523c
The bg
command is used in a Unix-based operating system to send a suspended or stopped job to the background, allowing it to continue running while the user can interact with the shell.
When a job is launched in the foreground, the shell waits for it to complete before accepting further commands. However, if a job is suspended or stopped using the ctrl-Z
keyboard shortcut, it means it is paused and no longer running actively. In this state, the shell cannot accept any commands related to the job.
To allow the suspended or stopped job to continue running in the background, the bg
command is used. By typing bg
followed by the job ID (which can be obtained using the jobs
command), the job is resumed in the background. This means the job will continue executing, but the user can still interact with the shell and issue other commands.
For example, let's say you have a long-running process (JOB1) that is currently suspended. Typing bg %1
(assuming JOB1 is the first job listed in the jobs
command output) will resume the job in the background. Now JOB1 will continue executing, while the shell prompt becomes available to accept further commands.