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 How to examine files on Linux Linux provides very useful options for viewing file attributes, such as owners and permissions, as well as file content. By Sandra Henry Stocker Oct 24, 2024 6 mins Linux how-to 8 easy ways to reuse commands on Linux Typing the same command again and again can become tiresome. Here are a number of ways you can make repeating commands – or repeating commands but with some changes – a lot easier than you might expect. By Sandra Henry-Stocker Oct 15, 2024 5 mins Linux news SUSE Edge upgrade targets Kubernetes and Linux at the edge SUSE Edge 3.1 includes a new stack validation framework and an image builder tool that are aimed at improving the scalability and manageability of complex Kubernetes and Linux edge-computing deployments. By Sean Michael Kerner Oct 15, 2024 6 mins Edge Computing Linux Network Management Software how-to Lesser-known xargs command is a versatile time saver Boost your Linux command line options and simplify your work with xargs, a handy tool for a number of data manipulation tasks. By Sandra Henry Stocker Oct 11, 2024 6 mins Linux PODCASTS VIDEOS RESOURCES EVENTS NEWSLETTERS Newsletter Promo Module Test Description for newsletter promo module. Please enter a valid email address Subscribe