bg Linux Command
Resumes a suspended job in the background.
What does bg do?
Resumes a suspended job in the background.
Syntax
bg [job_id]Practical example
bg %1Questions about bg
How do I resume a suspended job in the background?
Use `bg %jobid` to resume a suspended job in the background. Without a job ID, it resumes the most recently suspended job.
How do I suspend a running job?
Press `Ctrl+Z` to suspend the currently running job. Then use `bg` to resume it in the background.
How do I see background jobs?
Use `jobs -l` to list all jobs with their job IDs, PIDs, and status. The `+` indicates the current job, `-` the previous.
How do I bring a background job to the foreground?
Use `fg %jobid` to bring a background job to the foreground. Without a job ID, it brings the most recent background job.
What is the difference between bg and nohup?
`bg` resumes a suspended job in the background. `nohup` runs a command immune to hangups from the start. Use `nohup command &` for persistent background processes.
How do I run a command directly in the background?
Append `&` to any command: `command &`. The job is immediately placed in the background with a job ID.
How do I run a job in the background and disown it?
Use `command &` then `disown %jobid` to remove the job from the shell's job table. This prevents SIGHUP on shell exit.
How do I stop a background job?
Use `kill %jobid` to stop a background job, or `kill $(jobs -p)` to kill all background jobs of the current shell.
Related Process Commands
pkillSends a signal to processes based on name and other attributes.
fgBrings a background job to the foreground.
killallKills all processes matching a given name.
jobsLists active jobs (background and suspended processes) in the current shell.
killSends a signal to terminate a process by its PID.
niceRuns a command with a specified scheduling priority (niceness value).