Problem Statement
What does the & symbol do when appended to a command?
Explanation
The & symbol at the end of a command runs it in the background, immediately returning control to the terminal so you can continue working. The shell displays a job number and PID when the background job starts. Example: long_running_command & starts the command in the background.
Use jobs command to list background jobs, fg %jobnumber to bring a background job to foreground, and bg %jobnumber to resume a stopped background job. Press Ctrl+Z to suspend a foreground process, then use bg to continue it in the background. This workflow allows managing multiple tasks in a single terminal.
Note that background jobs still send output to the terminal, which can be disruptive. Redirect output to files: command > output.log 2>&1 & sends both stdout and stderr to a file. For persistent background jobs that survive terminal closure, use nohup: nohup command & prevents the job from receiving SIGHUP when the terminal closes.
Understanding background jobs is crucial for running long tasks like backups, data processing, or monitoring scripts without blocking your terminal. Combined with nohup, screen, or tmux, you can manage long-running processes effectively on remote servers.
Practice Sets
This question appears in the following practice sets:
