How to Fix Long Shutdown Time in Linux

Linux Taking too Long to Shut Down? Here’s the fix!

As the days go by, Linux is becoming more and more popular as an operating system. This is because of the security it provides, along with being an open-source OS. Improvements in the GUIs of Linux-based distributions are making them a widespread preference for desktop users as well as a tough competitor to windows.

Nowadays it’s common for desktop users to have dual boot operating systems, preferably Windows with a Linux distribution. Having dual boot has its advantages, however, it may result in longer shutdown times. 

This doesn’t have to be the only reason for it to occur, having an old computer also causes the same problems, even if you have a single Linux OS installed. 

Although shutdown times depend on a lot of factors, it doesn’t mean that there is no way to reduce it. You can be at ease because this guide is meant to educate you on how you can fix long shutdown time in Linux.

Without further wait, let’s start!

Understanding the Problem.

Having an idea of how your Linux system executes the shutdown procedure will help you better understand the problem along with the steps to fix long shutdown time in Linux. Before we talk about how shutdown works, we need to familiarize ourselves with two terms i.e. sigterm and sigkill.

Both sigterm and sigkill are related to shutting down processes. Sigterm tends to kill the process gracefully. What it means is that sigterm allows for the process to send information to its corresponding(parent and child) processes. This allows for the corresponding processes to finish their tasks before they get killed.

With sigkill, however, the processes get killed immediately, meaning that the process is terminated without allowing the corresponding child processes to finish. As a result of this, all corresponding child processes are unable to finish and thus, are terminated as well.

When you shut down your device, the system sends sigterm to terminate processes. This can end up increasing system shutdown times, as some processes may ignore sigterm and continue running afterwards. 

Normally your system will wait for these processes to shut down, however, if a certain amount of time has passed (referred to as delay), your system will automatically kill the processes by force.

Now that we have talked about how your system executes shutdown, we can focus on the methods to fix long shutdown time in Linux.

One requires an in-depth understanding of how your processes work and which processes are safe to kill, which vary from user to user.

The second method can be thought of as a quick fix. It works by tweaking the delay time before your system executes sigkill and forces the process to stop.

1. Terminating processes with a long shutdown time.

You can cut down long shutdown times on your Linux system by eliminating or reconfiguring the processes that take too long to terminate completely.

As long as you follow the steps correctly, you’ll be able to find the processes that need to be terminated or changed.

Bear in mind that this isn’t a one-size-fits-all solution, as the processes will vary for different users. Also, you’ll need to have a piece of in-depth knowledge about what you’re going to be terminating if you don’t want to lose any essential data. These commands are for Linux distributions that use systemd, for example, Ubuntu, Debian, etc.

With all prerequisites covered, let’s take a look at the steps:

  1. Open the command terminal by pressing Ctrl + Alt + T.
  2. Type the following command.
$ journalctl -rb -1
Long Shutdown Time in Linux

This will display the system logs of your last shutdown. You should see if there’s anything that looks out of the ordinary and deals with it accordingly, either by terminating or reconfiguring it.

In case you don’t see any logs, try to make sure that your Linux distribution uses systemd. If the journal logs don’t exist, then type the following command:

$ sudo mkdir /var/log/journal

This method may not be the best for everyone, as it requires extensive knowledge of the processes to be covered. If that’s the case with you, then no worries, as the second method is a quick fix to your problem.

2. Decreasing the default stop timeout.

This method can be thought of as a quick fix of sorts. As it doesn’t deal with the processes directly, rather it tweaks the delay time for sigkill. By reducing the delay time for sigkill, we can terminate processes faster. This significantly reduces the shutdown time.

The default delay time is set at 90 seconds. This can be changed by tweaking the value in the configuration file.

This method, like the previous one, is also for systemd users only. It is also advised that you copy the configuration file by typing the following command:

$ sudo cp /etc/systemd/system.conf /etc/systemd/system.conf.orig

With all the pieces in place, let’s take a look at the steps:

  1. Open the command terminal by pressing Ctrl + Alt + T.
  2. Type the following command:
$ sudo gedit /etc/systemd/system.conf
sudo gedit /etc/systemd/system.conf

Based on the desktop environment that you’re using, you can replace gedit with any text editor.

  1. Scroll down and find #DefaultTimeoutStopSec=90s in the file. Now, remove the hash(#) at the beginning and change the time to your liking, for example, 7 seconds.
#DefaultTimeoutStopSec=90s
  1. Click on Save and apply the change by typing the following command in the terminal.
$ systemctl daemon-reload
Linux terminal
  1. Enter your password to finalize the change.

With the steps followed correctly, you should now have reduced the shutdown time for your system. This method will prove to be an easier fix compared to the previous one.

We hope this guide helped you learn more about your Linux system and resolved your problem. Knowing how your system handles shutdown and how you can fix long shutdown time in Linux by tweaking the processes or decreasing delay time for sigkill will surely help you get one step closer to becoming a pro Linux user.

You can also make more out of your Linux system by learning how to zip and unzip folders by taking a look at this article.

If this guide helped you, please share it. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
ubuntu

How to Fix ‘Repository is not valid yet’ Error in Ubuntu Linux

Next Post
Remove Printer from Windows 10

How to Fix Cannot Remove Printers on Windows 10

Related Posts