fg Linux Command
Brings a background job to the foreground.
What does fg do?
Brings a background job to the foreground.
Syntax
fg [job_id]Practical example
fg %1Questions about fg
How do I bring a background job to the foreground?
Use `fg %jobid` to bring a specific background job to the foreground. Without a job ID, it brings the most recent background job.
How do I see my background jobs?
Use `jobs -l` to list all jobs with their IDs and status. Use `jobs -p` to see only the PIDs.
How do I suspend a foreground job?
Press `Ctrl+Z` to suspend the currently running foreground job. Then use `bg` to resume it in the background.
How do I switch between background jobs?
Use `fg %jobid` to bring a specific job to the foreground. You can switch between multiple background jobs.
What does fg without arguments do?
Running `fg` without arguments brings the most recently backgrounded job (marked with `+` in the jobs list) to the foreground.
How do I stop a foreground job?
Press `Ctrl+C` to send SIGINT and terminate the foreground job. Use `Ctrl+Z` to suspend instead.
How do I see the PID of a foreground job?
Use `jobs -l` to see the PID alongside the job ID. You can also use `ps` to see running processes.
What is the difference between fg and bg?
`fg` brings a background job to the foreground where you can interact with it. `bg` resumes a suspended job without bringing it to the foreground.
Related Process Commands
bgResumes a suspended job in the background.
jobsLists active jobs (background and suspended processes) in the current shell.
pkillSends a signal to processes based on name and other attributes.
niceRuns a command with a specified scheduling priority (niceness value).
killallKills all processes matching a given name.
reniceChanges the priority (niceness) of an already running process.