How to use nohup to run a process while logged out of Linux

Home > Search > How-to

Let's switch to the root account.

[user1@server1 ]# su - root


Using NOHUP (no hang up), let's signal the ping process to run 100 times in the background.

[root@server1 ]# nohup ping -c100 localhost &
[1] 15539
[root@server1 ]# nohup: ignoring input and appending output to 'nohup.out'


Now, let's exit the root account.

[root@server1 ]# exit


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, we can switch back to the root account.

[user1@server1 ]# su - root


If we list the contents of the PWD, there should be a new file named nohup.out.

[user1@server1 ]# ls


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 []: icmp_seq=95 ttl=64 time=0.031 ms
64 bytes from localhost []: icmp_seq=96 ttl=64 time=0.031 ms
64 bytes from localhost []: icmp_seq=97 ttl=64 time=0.037 ms
64 bytes from localhost []: icmp_seq=98 ttl=64 time=0.038 ms
64 bytes from localhost []: icmp_seq=99 ttl=64 time=0.035 ms
64 bytes from localhost []: 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


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter in the box below so that we can be sure you are a human.