In a graphical operating system like Windows or macOS, dealing with a frozen application is simple: you press a keyboard shortcut to open the Task Manager or Force Quit menu, find the frozen app, and click a button. But what happens when an application freezes on a headless Linux server that only has a command-line interface?
When a background script gets stuck in an infinite loop or a database process hangs and refuses to shut down normally, you must forcefully terminate it using the Linux terminal. This is done using a two-step process: first, you find the unique ID number of the rogue application, and second, you use the kill command to destroy it.
Step 1: Find the Process ID (PID)
Linux does not understand commands like “kill Firefox” or “kill Apache.” It only understands numbers. Every single application or background service running on a Linux system is assigned a unique, temporary numeric identifier called a Process ID (PID) the moment it launches.
To find the PID of the application you want to terminate, you must use the ps (process status) command combined with grep.
- Open your terminal.
- Type the following command, replacing firefox with the name of the frozen application:
ps aux | grep firefox
How this command works:
ps aux: This lists every single process currently running on the entire system, displaying who owns it and how much memory it is using.| grep firefox: This takes that massive list and filters it, only showing you the lines that contain the word “firefox”.
The terminal will output one or more lines of text. Look at the very first number on the line (usually a 4 or 5 digit number right next to your username). This number is your PID.
Step 2: Kill the Process Gently (SIGTERM)
Now that you have the PID (for example, let’s pretend the PID is 4598), you can issue the kill command. It is always best practice to try killing an application gently first, giving it a chance to save its data and shut down cleanly.
Type the following command and press Enter:
kill 4598
By default, this sends a SIGTERM (Signal Terminate) message to the application. It essentially politely asks the application to please wrap up what it is doing and exit. If the application is just running a bit slowly, it will usually comply and close within a few seconds.
Step 3: Force Kill the Process (SIGKILL)
If you sent the gentle kill command and the application is still frozen, it means the software is completely unresponsive and is ignoring the operating system’s polite requests. You must now use the nuclear option.
You can force the Linux kernel to immediately severe the application’s access to the CPU and memory, destroying it instantly without warning.
Type the following command and press Enter:
kill -9 4598
The -9 flag sends a SIGKILL signal. The application cannot intercept, ignore, or block this signal. It will instantly vanish from your system. (Note: Because it is killed instantly, any unsaved data within that application will be permanently lost).
The Shortcut: ‘killall’
If an application like Google Chrome has spawned twenty different background processes, finding and killing twenty individual PIDs is incredibly tedious. If you know exactly what the application is named, you can bypass the PID step entirely using the killall command.
killall chrome
This command searches the system for every single process associated with the name “chrome” and terminates them all simultaneously. Use this command with extreme caution; if you accidentally type a generic name, you could accidentally shut down critical system services.