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
jobscommand lists all background processes running in the current terminal session.^[600-developer__linux__centos7-command.md] Adding the-lflag provides additional information, such as process IDs (PIDs).^[600-developer__linux__centos7-command.md] - Suspending: The keyboard shortcut
Ctrl + Zinterrupts 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
bgcommand (e.g.,bg %num) resumes execution of a suspended job in the background, whereas thefgcommand (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]
Related Concepts¶
- [[Linux processes]]
- [[Bash scripting]]
- [[SSH]]
Sources¶
^[600-developer__linux__centos7-command.md]