Skip to content

Shell job control

Shell job control refers to the capability of the shell (such as Bash) to manage the execution state of commands, allowing users to control which processes run in the foreground and which run in the background.^[600-developer__linux__centos7-command.md]

Background Execution

To execute a command in the background, the ampersand symbol & is placed at the end of the command line.^[600-developer__linux__centos7-command.md] This converts the command into a background task immediately.

Managing Jobs

Users can interact with and manage background and suspended tasks using specific built-in commands and keyboard shortcuts:

  • Viewing Jobs: The jobs command lists all background processes running in the current terminal session.^[600-developer__linux__centos7-command.md] Adding the -l flag provides additional information, such as process IDs (PIDs).^[600-developer__linux__centos7-command.md]
  • Suspending: The keyboard shortcut Ctrl + Z interrupts a process currently running in the foreground, stops it, and places it in the background as a suspended task.^[600-developer__linux__centos7-command.md]
  • Resuming: The bg command (e.g., bg %num) resumes execution of a suspended job in the background, whereas the fg command (e.g., fg %num) brings a background or suspended job back to the foreground.^[600-developer__linux__centos7-command.md]

Persistence and Redirection

To ensure a process continues running even after the user logs out or the terminal session ends, the nohup command is used.^[600-developer__linux__centos7-command.md] This is typically combined with output redirection to handle standard output and standard error streams separately.^[600-developer__linux__centos7-command.md]

  • [[Linux processes]]
  • [[Bash scripting]]
  • [[SSH]]

Sources

^[600-developer__linux__centos7-command.md]