nohup Command in Linux
What is the nohup
command in Linux, and what does it do?
The
nohup
command stands for “no hang up.” It allows you to run a command or shell script in such a way that it continues to run even after you log out or close the terminal. This prevents the command from being terminated when the terminal session ends.
How do I use the nohup
command?
To use
nohup
, simply prepend it to the command you want to run. For example:nohup command_to_run &
The
&
symbol at the end puts the command in the background, allowing you to continue using the terminal while the command runs.
Where does nohup
send the output of the command?
By default,
nohup
redirects both standard output (stdout) and standard error (stderr) to a file namednohup.out
in the current directory. You can specify a different output file if desired.
Can I use nohup
with interactive commands or programs?
While
nohup
is typically used with non-interactive commands or scripts, you can use it with interactive commands. However, the behavior may be unpredictable, especially if the command expects input from the user. It’s generally recommended to avoid usingnohup
with interactive programs.
How can I check the status of a command running with nohup
?
Since
nohup
runs the command in the background, you can use standard Linux tools likeps
ortop
to check the status of the process. For example:ps aux | grep <command_name>
This will show you information about the process, including its PID (Process ID), which you can then use to manage or monitor the command.
nohup Command in Linux with Examples
Every command in Linux starts a process at the time of its execution, which automatically gets terminated upon exiting the terminal. Suppose, you are executing programs over SSH and if the connection drops, the session will be terminated, all the executed processes will stop, and you may face a huge accidental crisis. In such cases, running commands in the background can be very helpful to the user and this is where nohup command comes into the picture. nohup (No Hang Up) is a command in Linux systems that runs the process even after logging out from the shell/terminal.
Contact Us