Top.Mail.Ru

How to force close an application in Linux

How to force close an application in Linux

Despite the fact that Linux is traditionally considered a very stable system, even such an OS has problems. One of the most common is program freezing. The window simply freezes, the buttons cannot be pressed, the cursor spins endlessly. 

In such a situation, the quickest and easiest way is to close the window using the terminal. In this guide we will tell you how to do this. 

Step 1 — Find the process by name

The most convenient way is to use the pgrep command. It searches for processes by part of their name and can immediately show the full command:

pgrep -af text

For example, let’s imagine that the text editor built into Ubuntu has frozen. In this case the command will look like this:

pgrep -af gnome-text-editor

In response you will see lines like:

2893 /usr/bin/gnome-text-editor

Here 2893 is the PID, the unique process identifier.

If you are not sure of the exact name, you can “peek” using ps + grep:

ps aux | grep text

Life hack: for applications from Snap and Flatpak, the process names sometimes differ from the name in the menu. In such cases, the key helps -a at pgrep: it shows the entire run. This makes it much easier to understand what exactly to look for.

Step 2 — Try closing the application softly

First, let’s try to come to an amicable agreement and send the process a “polite” termination signal. This way the program will have time to save the files:

kill -TERM PID

The same can be done by name (without looking up the PID) if you are sure of the name:

pkill -TERM gnome-text-editor

Step 3 — if it doesn’t help, then use a more uncompromising option

Sometimes the application freezes and does not respond. Then you will have to use the “power” option:

kill -KILL PID

# equivalent to:

kill -9 PID

Or by name:

pkill -9 gnome-text-editor

Important: a hard termination does not give the program a chance to save. Use it only when the soft method does not work.

A few handy tricks

Sometimes several identical windows of the same program are running. To close them all at once:

killall gnome-text-editor

If the process is “hiding” and you can’t guess the search string, add the -f switch to pgrep, it searches using the full command:

pgrep -fl gnome

Another useful scenario: you just want to “see what’s there” and then close it precisely. At first:

pgrep -af chrome

Then select the desired PID from the list and send -TERM or -9 as above.

What to do if the system interface is completely frozen

It happens that the entire desktop does not respond — the panel, menu, list of windows. In this case, you can switch to the text console, terminate the “stubborn” processes and return back.

  1. Press Ctrl + Alt + F3 (or F4/F5 — depends on the system). A black screen will appear asking you to login.
  2. Enter your username and password.
  3. Find and terminate the stuck program as described above.
  4. Return to the GUI with Ctrl + Alt + F1 or Ctrl + Alt + F2 (Ctrl + Alt + F7 on some builds).

CONTENT:

Similar

All news

Похожее

Все новости

Adaxa Suite: подробный обзор ERP-системы корпоративного класса

Adaxa Suite — комплексная ERP-платформа для компаний, которым уже тесно в рамках простых учётных систем, но которые при этом не готовы идти в сторону дорогих корпоративных решений уровня SAP или Oracle. Изначально продукт создавался для среднего бизнеса, которому нужна большой набор функций, сквозная автоматизация процессов и надёжная архитектура без чрезмерной стоимости владения. Архитектура и техническая […]

Как заказать дополнительные IP-адреса на UFO.Hosting: пошаговая инструкция

По мере роста проекта одного IP-адреса может стать недостаточно. Это типичная ситуация для компаний, которые масштабируют инфраструктуру, запускают новые сервисы или разделяют внутренние процессы. В UFO.Hosting подключение дополнительных IP-адресов выполняется через биллинговую панель и занимает всего несколько минут. Важно: возможность для заказа дополнительных IP-адресов доступна для тарифов VPS начиная с Haedus. Зачем нужны дополнительные IP-адреса […]