Bird
Raised Fist0
Linux CLIscripting~20 mins

nohup for persistent processes in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Persistent Process Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this nohup command?
You run the command nohup sleep 10 & in a terminal. What will be the immediate output shown in the terminal?
Linux CLI
nohup sleep 10 &
Anohup: ignoring input and appending output to 'nohup.out'
Bsleep: command not found
CNo output, just returns to prompt immediately
DError: nohup requires a command argument
Attempts:
2 left
💡 Hint
Think about what nohup does with output when running a command in background.
🧠 Conceptual
intermediate
2:00remaining
Why use nohup with background processes?
Which of the following best explains why you use nohup when running a process in the background?
ATo run the process with higher priority
BTo speed up the process execution by using more CPU cores
CTo keep the process running even after the terminal is closed or you log out
DTo automatically restart the process if it crashes
Attempts:
2 left
💡 Hint
Think about what happens to normal background processes when you close the terminal.
🔧 Debug
advanced
2:00remaining
Why does this nohup command fail to keep process running?
You run nohup python myscript.py and then close the terminal, but the script stops immediately. What is the most likely reason?
Linux CLI
nohup python myscript.py
Anohup only works with compiled binaries, not scripts
BYou forgot to add & to run it in background
CThe script reads input from terminal and blocks, causing it to stop
DThe script has a syntax error and exits immediately
Attempts:
2 left
💡 Hint
Think about how to run commands in background with nohup.
📝 Syntax
advanced
2:00remaining
Which command correctly runs a persistent process with nohup and redirects output?
Choose the correct command to run myapp persistently with nohup, sending all output to app.log and running in background.
Anohup myapp & 2>&1 > app.log
Bnohup myapp & > app.log 2>&1
Cnohup myapp 2>&1 > app.log &
Dnohup myapp > app.log 2>&1 &
Attempts:
2 left
💡 Hint
Remember the order of output redirection and background symbol matters.
🚀 Application
expert
3:00remaining
How many lines will nohup.out contain after running this command?
You run nohup bash -c 'for i in {1..5}; do echo $i; sleep 1; done' and wait until it finishes. How many lines will the nohup.out file contain?
A5
B0
C1
D10
Attempts:
2 left
💡 Hint
Each echo prints one line, and output goes to nohup.out by default.

Practice

(1/5)
1. What is the main purpose of using nohup in Linux command line?
easy
A. To speed up the execution of a command
B. To stop a running process immediately
C. To display the output of a command in color
D. To run a command that keeps running after logout or terminal closes

Solution

  1. Step 1: Understand the function of nohup

    nohup stands for 'no hang up' and is used to run commands that continue running even after the user logs out or the terminal closes.
  2. 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.
  3. Final Answer:

    To run a command that keeps running after logout or terminal closes -> Option D
  4. Quick Check:

    nohup = persistent command run [OK]
Hint: Remember nohup means 'no hang up' to keep process alive [OK]
Common Mistakes:
  • Thinking nohup speeds up commands
  • Confusing nohup with output coloring
  • Assuming nohup stops processes
2. Which of the following is the correct syntax to run my_script.sh persistently in the background using nohup?
easy
A. nohup my_script.sh &
B. nohup & my_script.sh
C. my_script.sh nohup &
D. nohup my_script.sh

Solution

  1. Step 1: Recall the correct nohup syntax

    The correct way is to write nohup command & to run the command persistently in the background.
  2. 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.
  3. Final Answer:

    nohup my_script.sh & -> Option A
  4. Quick Check:

    nohup + command + & = correct syntax [OK]
Hint: Use nohup command & to run in background [OK]
Common Mistakes:
  • Placing & before the command
  • Omitting & to run in background
  • Misplacing nohup after the command
3. What will be the output file created when you run nohup sleep 60 & without redirecting output?
medium
A. No file is created
B. nohup.out
C. output.txt
D. sleep.log

Solution

  1. Step 1: Understand nohup default output behavior

    If no output redirection is given, nohup writes stdout and stderr to a file named nohup.out in the current directory.
  2. Step 2: Match this with options

    Only nohup.out matches the default output file. Others are incorrect or no file.
  3. Final Answer:

    nohup.out -> Option B
  4. Quick Check:

    Default nohup output file = nohup.out [OK]
Hint: Default nohup output file is nohup.out if not redirected [OK]
Common Mistakes:
  • Assuming no file is created
  • Thinking output goes to sleep.log
  • Confusing output.txt as default
4. You run nohup my_script.sh & but the process stops after you logout. What is the most likely reason?
medium
A. You did not redirect output, causing terminal hangup
B. You forgot to add & to run in background
C. You ran the command without nohup
D. You closed the terminal before the command started

Solution

  1. Step 1: Understand nohup and output redirection

    Without redirecting output, nohup writes to nohup.out, but if permissions or disk issues prevent this, the process may stop on logout.
  2. 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.
  3. Final Answer:

    You did not redirect output, causing terminal hangup -> Option A
  4. Quick Check:

    Output redirection needed to avoid hangup [OK]
Hint: Always redirect output to avoid hangup with nohup [OK]
Common Mistakes:
  • Ignoring output redirection importance
  • Assuming & alone keeps process alive
  • Thinking nohup always works without output file
5. You want to run backup.sh persistently, save all output to backup.log, and avoid terminal clutter. Which command should you use?
hard
A. ./backup.sh > backup.log 2>&1 &
B. nohup ./backup.sh & > backup.log 2>&1
C. nohup ./backup.sh > backup.log 2>&1 &
D. nohup ./backup.sh 2>&1 > backup.log &

Solution

  1. Step 1: Understand output redirection with nohup

    To save both standard output and errors to a file, use command > file 2>&1. The ampersand & runs the command in background.
  2. 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.
  3. Final Answer:

    nohup ./backup.sh > backup.log 2>&1 & -> Option C
  4. Quick Check:

    nohup + redirect stdout/stderr + & = correct [OK]
Hint: Redirect output before & to save logs with nohup [OK]
Common Mistakes:
  • Placing & before output redirection
  • Forgetting nohup for persistence
  • Reversing stderr and stdout redirection order
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard