What if your long tasks never stopped just because you closed the terminal?
Why nohup for persistent processes in Linux CLI? - Purpose & Use Cases
Imagine you start a long task on your computer, like downloading a big file or running a script. Then you close the terminal or log out. Suddenly, the task stops and you lose all progress.
Manually running commands without protection means your work stops when the terminal closes. You must restart tasks again and again, wasting time and risking errors.
The nohup command lets your task keep running even if you close the terminal. It ignores hangup signals, so your process stays alive and finishes without interruption.
python long_script.py
# closes terminal -> script stopsnohup python long_script.py &
# script keeps running after terminal closesYou can start important tasks and safely disconnect, knowing they will finish on their own.
Starting a backup or data processing job on a remote server, then logging out without stopping the job.
Closing terminals usually stops running tasks.
nohup keeps tasks running after logout.
This saves time and avoids restarting work.
Practice
nohup in Linux command line?Solution
Step 1: Understand the function of
nohupnohupstands for 'no hang up' and is used to run commands that continue running even after the user logs out or the terminal closes.Step 2: Compare options with this definition
Only "To run a command that keeps running after logout or terminal closes" matches this purpose. The other options describe unrelated functions.Final Answer:
To run a command that keeps running after logout or terminal closes -> Option DQuick Check:
nohup = persistent command run [OK]
- Thinking nohup speeds up commands
- Confusing nohup with output coloring
- Assuming nohup stops processes
my_script.sh persistently in the background using nohup?Solution
Step 1: Recall the correct nohup syntax
The correct way is to writenohup command &to run the command persistently in the background.Step 2: Check each option
nohup my_script.sh & matches the correct syntax. nohup & my_script.sh places & before the command incorrectly. my_script.sh nohup & misplaces nohup. nohup my_script.sh runs nohup but not in background.Final Answer:
nohup my_script.sh & -> Option AQuick Check:
nohup + command + & = correct syntax [OK]
- Placing & before the command
- Omitting & to run in background
- Misplacing nohup after the command
nohup sleep 60 & without redirecting output?Solution
Step 1: Understand nohup default output behavior
If no output redirection is given,nohupwrites stdout and stderr to a file namednohup.outin the current directory.Step 2: Match this with options
Only nohup.out matches the default output file. Others are incorrect or no file.Final Answer:
nohup.out -> Option BQuick Check:
Default nohup output file = nohup.out [OK]
- Assuming no file is created
- Thinking output goes to sleep.log
- Confusing output.txt as default
nohup my_script.sh & but the process stops after you logout. What is the most likely reason?Solution
Step 1: Understand nohup and output redirection
Without redirecting output,nohupwrites tonohup.out, but if permissions or disk issues prevent this, the process may stop on logout.Step 2: Analyze options
You did not redirect output, causing terminal hangup correctly points to output redirection issues causing hangup. You forgot to add & to run in background is wrong because & was added. You ran the command without nohup is wrong because nohup was used. You closed the terminal before the command started is unlikely as process starts immediately.Final Answer:
You did not redirect output, causing terminal hangup -> Option AQuick Check:
Output redirection needed to avoid hangup [OK]
- Ignoring output redirection importance
- Assuming & alone keeps process alive
- Thinking nohup always works without output file
backup.sh persistently, save all output to backup.log, and avoid terminal clutter. Which command should you use?Solution
Step 1: Understand output redirection with nohup
To save both standard output and errors to a file, usecommand > file 2>&1. The ampersand & runs the command in background.Step 2: Check each option's correctness
nohup ./backup.sh > backup.log 2>&1 & correctly places redirection before &. nohup ./backup.sh & > backup.log 2>&1 misplaces & before redirection. ./backup.sh > backup.log 2>&1 & lacks nohup. nohup ./backup.sh 2>&1 > backup.log & reverses redirection order, which is incorrect.Final Answer:
nohup ./backup.sh > backup.log 2>&1 & -> Option CQuick Check:
nohup + redirect stdout/stderr + & = correct [OK]
- Placing & before output redirection
- Forgetting nohup for persistence
- Reversing stderr and stdout redirection order
Ready to prove it?
Pass the test and this pattern moves unknown
