When you disown a Linux process in bash, you keep it from being terminated when you log out and allow it to finish on its own. This post shows how to use the disown command. Credit: The Preiser Project When you want a process to continue running even after you log off a Linux system, you have a couple options. One of them is to use the disown command. It tells your shell to refrain from sending a HUP (hangup) signal to the process when you log off. So, the process continues running. This can be very handy whenever you start a process, and then for some reason you can’t stay logged in and wait until it finishes. The disown command is a shell built-in. This means that you don’t have to install it to use it, but it also means that it won’t be available if you use a shell that doesn’t support it. For those of us using bash and related shells (zsh, ksh etc.), disown should be available, and you can verify this with a command like the following that lists shell built-ins and then looks for “disown”: $ show_builtins | grep disown disown [-h] [-ar] [jobspec ... | pid > test [expr] Unlike nohup, which has pretty much the same effect, disown is used after you’ve started a process. Just specify the process ID with the disown command: $ ps -ef | grep long-loop shs 799217 1 0 11:04 ? 00:00:00 /bin/bash /home/shs/bin/bigjob $ disown 799217 The process will continue running after you log off, and if it hasn’t finished by the time you log in again, will still be running until it’s completed. In fact, it won’t even be affected when you log off again because it will not be associated with your current shell. Check out disown If you’d like to see how disown works, you can set up a simple loop in a script. Here’s an example: #!/bin/bash while true do date >> my.log sleep 600 done This script adds the current date and time to a file named “my.log” every 10 minutes and has no stopping point. You can start it in the usual way: $ ./my-loop Then, when you’re ready to log off you can maybe run off somewhere, suspend your process with ^z (hold control key and press “z”). After that, list your processes: $ ps PID TTY TIME CMD 801593 pts/3 00:00:00 bash 801812 pts/3 00:00:00 long-loop 801816 pts/3 00:00:00 sleep Then use the disown command with the script’s process ID: $ disown 801812 Note that, if you run your process in the background from the start (e.g., my-loop &), you don’t need to use the ^z. Terminating a disowned process Most processes will not, of course, be designed to run forever. They’ll probably finish before you log back in again. In the case of this example loop, you would eventually need to use a bit of force to stop it once you’ve logged off and back on. The “sure kill” -9 option should do this for you: $ kill 801812 $ ps PID TTY TIME CMD 801593 pts/3 00:00:00 bash 801812 pts/3 00:00:00 long-loop Some options You might have noticed in the output of the show_builtins command above that the disown command has several options. The -a option will disown all backgrounded processes while -r means it will only disown running (not stopped) processes. In both cases, the jobs being disowned will no longer show up when you type "jobs". When you use the -h option, on the other hand, the job will not removed from the jobs list, though the shell will still refrain from sending an HUP signal to it when you log out. Related content how-to Compressing files using the zip command on Linux The zip command lets you compress files to preserve them or back them up, and you can require a password to extract the contents of a zip file. By Sandra Henry-Stocker May 13, 2024 4 mins Linux opinion NSA, FBI warn of email spoofing threat Email spoofing is acknowledged by experts as a very credible threat. By Sandra Henry-Stocker May 13, 2024 3 mins Linux how-to The logic of && and || on Linux These AND and OR equivalents can be used in scripts to determine next actions. By Sandra Henry-Stocker May 02, 2024 4 mins Linux how-to Using the apropos command on Linux By Sandra Henry-Stocker Apr 24, 2024 3 mins Linux PODCASTS VIDEOS RESOURCES EVENTS NEWSLETTERS Newsletter Promo Module Test Description for newsletter promo module. Please enter a valid email address Subscribe