When to use nohup
Use nohup for simple commands that should ignore hangup signals. Redirect input and output explicitly, then verify the process and its logs; it is not a full service supervisor or a replacement for persistent terminal sessions.
Syntax
nohup COMMAND [ARGUMENTS...]Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.
Common options and arguments
Usage examples
Run test task with explicit output
nohup sleep 120 > ./demo.out 2>&1 < /dev/null &A temporary task runs in the background with output redirected and no terminal input.
Run the prepared script
nohup ./report.sh > ./report.log 2>&1 < /dev/null &The report script runs with both output streams saved to its log.
View the result of the script
tail -n 20 ./report.logRecent log lines are inspected to verify what the detached script reported.
Notes and limitations
- nohup protects against SIGHUP, but is not a service manager and does not guarantee the survival of the process under any exit policy.
- For permanent services, use systemd; for interactive work - tmux or screen.
Common questions and troubleshooting
Does nohup automatically restart a crashed task?
No. It changes hangup handling but provides no restart policy. Use a service manager for supervised long-running work.
Why did the task still stop after logout?
Session policy, another signal, an error or missing input can still end it. Inspect logs and use the appropriate server service mechanism.
Further help
Options vary by version and distribution. Check the installed documentation with this command: man nohup.