Unix and Linux operating systems provide the nohup
command in order to implement the nohup signal. The signal and command name are the same. The nohup command is created to prevent hop signal which is used to hang up
. The hang-up signal kills all processes related to a user being killed after the user logs out. BY using the nohup signal a command can be executed even the owner user logs out.
nohup Command Syntax
The nohup command has very simple syntax as a basic command.
nohup OPTION COMMAND
- OPTION is opitonal and generally not used as it is only used to print version and help information.
- COMMAND is the command or script which will receive nohup signal.
nohup Command Example
The nohup command is executed in the terminal and the standard output is /dev/null
. As you expect the standard input of the nohup command is the terminal where different commands or scripts are provided. The standard error output is the terminal too which means the errors are printed in the terminal. By default, the nohup command output is stored inside the current user’s home directory inside the .nohup
file. The .nohup file is a hidden file.
In the following example, we ping the “google.com” and this ping operation continues event the user logs out.
$ nohup ping google.com &
Save nohup Output To Different File
By default, the nohup command output is saved into the $USER/.nohup or user home directory .nohup
file. We can also save the command output into different files. The >
redirect operator is used to save nohup command output to the specified file.
$ nohup ping google.com > /home/ismail/ping.out &
Read nohup Output File
The nohup file output is stored as a text file. So reading the outpğut file is very easy. We can use the cat
command in order to read nohup command output file like below.
$ cat /home/ismail/nohup.out
Also, text editor can be used to read nohup command output without a problem.
kill nohup Processes
Event nohup is used to run a command or script in the background even the user logsout there are ways to kill the nohup process. The kill
command can be used to kill nohup process explicitly. First the process ID should be listed with the ps aux
command like below.
$ ps aux | grep ping
The process ID is provided to the kill
command with the -9
option which is a TERM
signal used to terminate a given process.
$ kill -9 2321