0
0
Linux CLIscripting~15 mins

fg and bg commands in Linux CLI - Mini Project: Build & Apply

Choose your learning style9 modes available
Using fg and bg Commands to Manage Background and Foreground Processes
📖 Scenario: You are working in a Linux terminal and want to manage running programs efficiently. Sometimes you want to pause a program and send it to the background, and other times you want to bring a background program back to the foreground to interact with it.
🎯 Goal: Learn how to use the fg and bg commands to move processes between the foreground and background in a Linux shell.
📋 What You'll Learn
Create a simple command that runs a program in the foreground
Pause the running program and send it to the background
Bring the background program back to the foreground
Display the current jobs and their statuses
💡 Why This Matters
🌍 Real World
Managing multiple tasks in a terminal without opening new windows or tabs is common for system administrators and developers.
💼 Career
Knowing how to control foreground and background processes is essential for efficient command-line work and automation.
Progress0 / 4 steps
1
Start a Long-Running Command in the Foreground
Type the command sleep 100 to start a program that runs for 100 seconds in the foreground.
Linux CLI
Need a hint?

The sleep command pauses for a number of seconds. This will keep the terminal busy.

2
Pause the Running Command and Send It to the Background
While sleep 100 is running, press Ctrl+Z to pause it. Then type bg to send it to the background.
Linux CLI
Need a hint?

Pressing Ctrl+Z pauses the program and puts it in the background in a stopped state. The bg command resumes it in the background.

3
Check the Status of Background Jobs
Type jobs to list all current background jobs and their statuses.
Linux CLI
Need a hint?

The jobs command shows all jobs started in the current shell and their states.

4
Bring the Background Job Back to the Foreground
Type fg to bring the background sleep 100 process back to the foreground.
Linux CLI
Need a hint?

The fg command brings the most recent background job to the foreground so you can interact with it.