Send to background.

      bg [jobspec ...]
      job ... &

Appending an ampersand ( & ) to the command runs the job in the background.

Resume each suspended job jobspec in the background, as if it had been started with &.

bg takes a “jobspec” available from jobs, not a PID.

If jobspec is not present, the shell’s notion of the current job is used.

bg jobspec returns 0 unless run when job control is disabled or, when run with job control enabled, any specified jobspec was not found or was started without job control.

To kill a specific background job use, kill %jobspec.

bg is a BASH shell builtin and a ZSH shell builtin, to display your local syntax from the bash prompt type: help bg


Put the job with job id 0 in the background:

$ bg %0

To start a new process in the background you can do:

$ long_running_command &

Send the current foreground job to the background using CTRL-Z and bg:

$ long_running_command

$ Ctrl-Z

$ [2]+ Stopped long_running_command
$ bg

View all the background jobs using jobs:

$ jobs
[1]   Running     long_running_command &
[2]-  Running     someothercommand &

Bring a background job to the foreground. When executed without arguments, this will take the most recent background job to the foreground:

$ fg

Kill job #2:

$ kill %2

“Keep your eyes on the stars, and your feet on the ground” ~ Theodore Roosevelt

Related macOS commands

fg - Send job to foreground.
jobs - List active jobs.
taskpolicy - Execute a program with an altered I/O or scheduling policy.
wait - Wait for a process to complete.

Copyright © 1999-2024
Some rights reserved