Course contentsShow
← Linux
Lesson 75 of 1,8191. Shell Architecture and Process EnvironmentFree lesson

Job Control and Backgrounding in TTY

Move processes between foreground and background while managing their access to terminal input.

In this lesson, you will learn how to shift active tasks between your foreground terminal view and the background to maintain full control over your interactive session.

When you run a command in your shell, it typically occupies your "foreground." This means the process is attached to your terminal's standard input—it’s listening to your keyboard, and any text it prints appears directly on your screen. If you start a process that takes a long time, your terminal becomes "blocked," preventing you from typing new commands.

Moving Jobs to the Background

You can "background" a running process by first suspending it. Press Ctrl+Z on your keyboard. This sends a SIGTSTP signal to the process, freezing it and returning you to your shell prompt. To continue that process in the background, type bg. The process will keep running, but it is now detached from your immediate keyboard input, allowing you to use the terminal for other work.

Bringing Jobs to the Foreground

If you need to check on a background process or interact with it again, use the fg command. This brings the most recent background job back into the foreground, reconnecting its standard input to your terminal.

Managing Access

The terminal acts as a gatekeeper. Only one process can be the "foreground" process at any time; that is the only one permitted to read from your keyboard. If you attempt to send input to a background process, the terminal line discipline will often intervene to protect the state of your session.

Try this sequence to see it in action:

  1. Run cat (it will wait for input).
  2. Press Ctrl+Z to suspend it.
  3. Run bg to push it to the background.
  4. Try to type; notice your shell ignores the input for cat and processes it for your command line instead.
  5. Run fg to bring cat back and interact with it again.

This flow allows you to multitask without needing multiple terminal windows, keeping your workspace organized while maintaining strict control over which process "owns" the input stream.

Key Takeaway: Use Ctrl+Z to suspend a task, bg to run it in the background, and fg to return it to the foreground to regain control of your terminal's input stream.