The nohup command in Linux allows you to run processes in the background that will continue executing even after you log out of the system. The name "nohup" stands for "no hangup", indicating that the process will not be terminated or "hang up" when the terminal exits.
How Nohup Works
By default, Linux shells like Bash will send a SIGHUP signal to background processes when the shell exits. This signal causes the processes to terminate. The nohup command runs your specified process and redirects any SIGHUP signals to /dev/null so that the process ignores them and continues running.
Some key things to know about nohup:
- It allows the background process to keep running after you log out or close the terminal
- Output that would normally go to the terminal is redirected to a file called
nohup.outby default - The process runs with the same permissions and environment as if launched normally
Nohup Command Syntax
The basic syntax for nohup is:
nohup command options > output_file 2>&1 &
Breaking this down:
nohupruns the given command immune to hangup signalscommand optionsis the process you want to run>redirects standard output to the output file2>&1redirects stderr (standard error) to stdout&runs the process in the background
If no output file is given, output goes to nohup.out in the current directory.
Some examples:
nohup ping google.com &
nohup python script.py --params > out.log 2>&1 &
Keeping Processes Running with Nohup
One very common use case for nohup is keeping long-running processes like servers and databases running even after you log out of an SSH session:
nohup node server.js &
Now you can safely log out while the Node.js server keeps running. The output is saved to nohup.out.
Similarly, you could run a MySQL database server that persists in the background:
nohup mysqld &
The mysqld process will continue running after you exit SSH.
Checking Background Jobs
There are a few ways to check the status of jobs launched with nohup:
1. ps command – Lists information about running processes:
ps aux | grep nohup
This will display the process ID, owner, command details, etc.
2. jobs command – Shows current shell background jobs:
jobs
3. pgrep – Finds processes by name:
pgrep -afl nohup
The -a flag shows the full command. -f searches full argument lists.
4. Check nohup.out – Tail the nohup.out file in the current directory to see command output:
tail nohup.out
Stopping Nohup Processes
To terminate a process launched with nohup, you need to find its Process ID (PID) and kill it.
First look up the PID:
pgrep <process_name>
Then send a kill signal with kill:
kill <pid>
For example:
pgrep mysqld
> 7865
kill 7865
This will terminate the background MySQL server.
You can also use signals like SIGINT and SIGTERM instead of the default SIGKILL.
Advantages of Nohup
Using nohup to manage long-running processes has several advantages:
Robustness – Processes persist across SSH logouts and terminal closings.
Asynchronicity – Runs processes in the background freeing up the terminal.
Output Logging – Stdout and stderr get written to a file for later debugging.
Easy Daemonizing – Turns processes into daemons using only basic shell capabilities.
Portability – Included by default in Linux and macOS, and available via Cygwin on Windows.
Overall nohup is a simple but powerful utility for Linux users and administrators. Understanding it unlocks new ways of working.
Disadvantages of Nohup
Of course, nohup also has some downsides to consider:
Can forget about processes – Out of sight out of mind – background jobs get overlooked.
No log rotation – nohup.out files grow indefinitely which can fill up disks.
Signals ignored – Processes won‘t react to signals like SIGHUP, SIGINT, etc unless explicitly handled.
PID tracking – Easy to lose track of background PID numbers leading to orphaned processes.
Contention – On a shared multi-user system you could monopolize resources.
So while nohup is very useful, make sure to periodically monitor and clean up old jobs. Use resource monitoring tools to check for runaway processes.
Conclusion
Learning to properly use the nohup command opens up new ways of working with Linux. You can launch long-running database servers, web apps, utilities, and more that persist in the background between sessions.
Key takeaways include:
- Nohup prevents hangup signals from terminating processes when the shell exits
- It runs jobs in the background and logs output to
nohup.out - Useful for servers, databases, and other persistent daemons
- Requires care to manage resources and clean up old processes
Take time to experiment with nohup. Used judiciously, it can make administering Linux much more efficient. Consult man nohup for even more usage details.


