Start long-task so it ignores SIGHUP.
Combine standard output and standard error in task.log, and return the prompt without waiting.
Which command is appropriate?
nohup starts a command configured to ignore SIGHUP. Add & for asynchronous execution and redirect both streams explicitly.
Detailed explanation
nohup long-task > task.log 2>&1 &Correct. nohup protects the process, the redirections combine output, and & returns the prompt.
Correct. nohup protects the process, the redirections combine output, and & returns the prompt.
long-task > task.log 2>&1Incorrect. It does not ignore SIGHUP and it waits for the command in the foreground.
Incorrect. It does not ignore SIGHUP and it waits for the command in the foreground.
nohup long-task > task.log 2>&1Incorrect. nohup is present, but without & the current shell waits for completion.
Incorrect. nohup is present, but without & the current shell waits for completion.
long-task &> task.logIncorrect. &> combines output in Bash but does not configure nohup to ignore SIGHUP.
Incorrect. &> combines output in Bash but does not configure nohup to ignore SIGHUP.
Try it yourself
An example you can run in a temporary verification environment.
nohup bash -c 'printf done' > /tmp/kp-nohup.log 2>&1 & TASK_PID=$!; wait "$TASK_PID"; cat /tmp/kp-nohup.log; rm /tmp/kp-nohup.logExpected result
doneKey points
- nohup ignores SIGHUP
- & makes the command asynchronous
- Redirect both output streams
Notes
- Environment: GNU coreutils 9.x / Bash 5.2
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.