disown command in linux

rasikmhetre
2 min readSep 4, 2021

--

If you want your process/job to be in running state consistently even after you logged out from the server, then you may use disown command.

So this command will remove your job from the shell’s job table.

Before firing up disown command, notice the parent process id of that process/job then logout, after that login back to the server check the parent process id, it should be 1(init).

I ran ping command twice in background, below are the processes

[root@atyourstation ~]# ps -ef|grep ping
root 27914 27574 0 17:17 pts/2 00:00:00 ping facebook.com
root 27929 27574 0 17:17 pts/2 00:00:00 ping facebook.com

After this i ran disown -r, which will remove all running process from the shell’s job table.

Logout from the server, i.e. sending the SIGHUP signal to the the shell by firing “logout” command or (Ctrl+D)

Login back and check the process

[root@atyourstation ~]# ps -ef|grep ping
root 27914 1 0 17:17 ? 00:00:00 ping facebook.com
root 27929 1 0 17:17 ? 00:00:00 ping facebook.com

If you notice the parent process id of those processes has been changed, it’s 1 now which is init.

If you have to remove a specific job from shell’s job table and run it consistently even after logout, then every job has a job id, you can feed it to the disown command. I have demonstrated it below:

[root@atyourstation ~]# jobs
[2]+ Running ping google.com > /dev/null &
[root@atyourstation ~]#
[root@atyourstation ~]# disown -h %2
[root@atyourstation ~]#
[root@atyourstation ~]# ps -ef|grep ping
root 28355 28322 0 17:22 pts/3 00:00:00 ping google.com

Logout from the server by sending the SIGHUP signal to the shell by firing “logout” command or (Ctrl+D) and then login back to the server and check that process again, you should see that parent process id should be init i.e. 1

[root@atyourstation ~]# ps -ef|grep ping
root 28778 1 0 17:29 ? 00:00:00 ping google.com

Thanks to the source from where i learned this, it is very nicely and deeply explained here, https://www.slashroot.in/disown-command-linux-explained-example-usage

--

--