
The nohup (no hang up) command instructs a process to run after disconnecting the SSH session (psuedo tty). This is almost always used along with the & character to run the job in the background.
For example, let's tell the ping process to run 100 times in the background.
[root@server1 ]# nohup ping -c 100 localhost &
[1] 15539
[root@server1 ]# nohup: ignoring input and appending output to 'nohup.out'
And then exit the SSH connection.
[root@server1 ]# exit
logout
It will take about 2 minutes for the ping process to complete, so before 2 minutes have elapsed, if we us the ps command with the -ef or ax options and pipe the output to grep, we can see that the process is still running.
[user1@server1 ]# ps -ef | grep ping
root 15539 1 0 16:39 pts/0 00:00:00 ping -c100 localhost
user1 15542 15515 0 16:40 pts/0 00:00:00 grep --color=auto ping
After 2 minutes have elapsed, if we list the contents of the PWD, there should be a new file named nohup.out.
[user1@server1 ]# ls
nohup.out
If we view view the nohup.out command, we can see that it contains the 100 pings.
[user1@server1 ]# tail nohup.out
64 bytes from localhost [127.0.0.1]: icmp_seq=95 ttl=64 time=0.031 ms
64 bytes from localhost [127.0.0.1]: icmp_seq=96 ttl=64 time=0.031 ms
64 bytes from localhost [127.0.0.1]: icmp_seq=97 ttl=64 time=0.037 ms
64 bytes from localhost [127.0.0.1]: icmp_seq=98 ttl=64 time=0.038 ms
64 bytes from localhost [127.0.0.1]: icmp_seq=99 ttl=64 time=0.035 ms
64 bytes from localhost [127.0.0.1]: icmp_seq=100 ttl=64 time=0.032 ms
--- localhost ping statistics ---
100 packets transmitted, 100 received, 0% packet loss, time 98999ms
rtt min/avg/max/mdev = 0.020/0.031/0.050/0.007 ms
Did you find this article helpful?
If so, consider buying me a coffee over at