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 find files on Linux There are many options you can use to find files on Linux, including searching by file name (or partial name), age, owner, group, size, type and inode number. By Sandra Henry Stocker Jun 24, 2024 8 mins Linux opinion Linux in your car: Red Hat’s milestone collaboration with exida With contributions from Red Hat and critical collaborators, the safety and security of automotive vehicles has reached a new level of reliability. By Sandra Henry Stocker Jun 17, 2024 5 mins Linux how-to How to print from the Linux command line: double-sided, landscape and more There's a lot more to printing from the Linux command line than the lp command. Check out some of the many available options. By Sandra Henry Stocker Jun 11, 2024 6 mins Linux how-to Converting between uppercase and lowercase on the Linux command line Converting text between uppercase and lowercase can be very tedious, especially when you want to avoid inadvertent misspellings. Fortunately, Linux provides a handful of commands that can make the job very easy. By Sandra Henry Stocker Jun 07, 2024 5 mins Linux PODCASTS VIDEOS RESOURCES EVENTS NEWSLETTERS Newsletter Promo Module Test Description for newsletter promo module. Please enter a valid email address Subscribe