Regístrese ahora para una mejor cotización personalizada!

How to kill a process in Linux

Abr, 19, 2023 Hi-network.com
Getty Images/d3sign

Every application and service on your Linux machine runs as a process. Your web browser, email client, Spotify, Zoom, Slack, LibreOffice, your desktop environment...they all run as processes. And, for the most part, those processes run fairly smoothly. Every so often, however, you might find a process (an application or a service) that goes astray and either slows down your system or causes other problems (such as a locked-up desktop). 

Also: Ready to ditch Windows for Linux? This is the ideal distro for you

When that happens, you need to be able to kill those runaway processes. Now, most Linux desktop environments include a GUI tool that makes killing a process a simple matter of selecting the process and then selecting Kill.

Killing a process from within the Pop!_OS desktop GUI.

Image: Jack Wallen/

That's all fine and good, but what happens when you can't access the GUI because a runaway process is gobbling up your system memory? That's when you turn to the command line. 

Also: The best Linux laptops

I'm going to show you two simple ways to kill a Linux process from the command line. You'll be surprised at how easy it actually is.

How to use the kill command

1. Using the kill command

The first method I will show you uses the kill command. The kill command kills processes by way of their PID (process ID). A typical kill command looks like this:

kill PID

Where PID is the process ID for the process in question. 

2. How to kill Firefox with the kill command

You're probably asking yourself, "Where do I locate the PID?" Good question. Here's how. Let's say the problem application is the Firefox web browser. To kill Firefox with the kill command, open a terminal window and locate the PID with:

ps aux grep firefox

The breakdown of the above command is simple:

  • ps: reports a snapshot of the currently running processes.
  • aux:lifts the BSD-style "only yourself" restriction as well as the BSD-style "must have a tty" restriction and lists all processes in the user list.
  • :pipe the output of ps to the next command (in this case, grep)
  • grep: match only the process with the sting that follows.
  • firefox: the process we're searching for.

Of course, in the case of Firefox, you'll see a process for every single tab you have open. To actually kill Firefox, you need to locate the PID of the very first listed. That listing will look something like this:

jack       21960  7.6  2.5 14450944 825944 ?     SNl  Jun12 122:44 firefox

The PID is the first number (directly to the right of the username). So, for the above example, the kill command would be:

kill 21960

The above command should kill Firefox.

How to use the killall command

1. Using the killall command for firefox

This method is considerably easier. Instead of using the PID of the process, you use the name of the process. So, if we want to kill the process named firefox, the command would be:

killall firefox

If you want to be safe, you can force killall to verify that you want to kill the command using the interactive option like so:

killall -i firefox

Answer y to the question, and the Firefox process will be killed. 

Believe it or not, that's how easy it is to kill a runaway process (or any process, for that matter) on Linux. Yes, there are more options available for each of those commands, but what I've outlined above will get you started. To learn more about each command, read the man pages with man kill and man killall.

See also

How to install Ubuntu Linux (It's easy!)How to run a Windows app on Linux with WineHow to get started with Git on LinuxHow to kill a process in Linux
  • How to install Ubuntu Linux (It's easy!)
  • How to run a Windows app on Linux with Wine
  • How to get started with Git on Linux
  • How to kill a process in Linux

tag-icon Etiquetas calientes: Servicios y Software Sistemas operativos LINUX

Copyright © 2014-2024 Hi-Network.com | HAILIAN TECHNOLOGY CO., LIMITED | All Rights Reserved.