What is jobs and fg/bg in Linux?

In Linux, the jobs command is used to list the currently running jobs in the background or stopped processes that have been started from the terminal. Each job is associated with a unique job number, and you can manage these jobs using foreground (fg) and background (bg) commands.

The fg command is used to bring a background job to the foreground, allowing you to interact with it directly. On the other hand, the bg command is used to resume a stopped job in the background, allowing it to run without occupying the terminal.

Example of Using jobs, fg, and bg Commands:

# Start a long-running command in the background sleep 300 & # Check the list of jobs jobs # Bring the job with job number 1 to the foreground fg %1 # Stop the job with Ctrl+Z, which pauses it and puts it in the background # Then, to resume it in the background, use: bg %1

jobs fg bg Linux command line process management