How To: Kill Processes By Their PID (Process ID)

Today’s article is one my regulars will be expecting, as it is an article that teaches you how to kill processes by their PID (Process ID). This shouldn’t be a long or complicated article and I’d like to think a beginner can understand what it is that we’ll be doing.

If you aren’t familiar with a process PID, you should read the article that I wrote just so that I could write this article:

Find An Application’s Process ID (PID)

Seriously, if you’re at all unsure, read that article. You could even consider that article the first part of this article, except I didn’t want to make my article long. Besides, it’s quite likely I’ll be referring to PIDs in the future.

NOTE: The subject we’ll be approaching today can be quite complicated. In this case, there are all sorts of ways to kill processes. Because of this, we’ll just be covering a couple of very easy ways to kill processes by using their PID. 

Why would you want to do this? 

Well, like it or not, sometimes applications freeze and sometimes applications refuse to close. This is true on every operating system. It can (and probably will) happen. I just tried a pinball application last night and it refused to close. (I closed it using the GUI task manager, not via the PID. Shh!)

Why would you want to kill processes by their PID, especially when you can also ‘killall‘ processes by their name?

Sometimes, you have processes with names like this:

Instead of trying to close that with a command, it has a PID of its own and can be closed using that. It’s so much easier to use the PID for this that you might as well learn how to do it now. Again, it won’t be all that complicated. I’ll do what I can to explain just a couple of choices while we all safely ignore the many other options.

NOTE: This isn’t quite the article I intended to write, so there’s that. The people on the Linux.org forum will know what I mean. This is largely due to my horrible memory.

Kill Processes By Their PID:

Yeah, this is a terminal thing. As such, you’re going to need an open terminal. In most distros, you can just press CTRL + ALT + T and that should be enough to open up your default terminal emulator.

With your terminal now open, let’s have a look at the tool we’ll be using:

If you won’t want to look, the kill command describes itself like this:

kill – send a signal to a process

Handily enough, that’s what we’ll be doing. We’ll be sending a single to a process, specifically to kill the process. You can send other signals. You can send quite a few different signals. Enter this into your terminal:

But, we’re only going to concern ourselves with 9 and 15. Those are the only two we’re going to worry about today. The syntax of the kill command would look like this:

Of course, you’re going to need to know the PID. If you read the article linked in the beginning section, you’d know how to do that. But…

For the sake of this article, we’ll be using ‘shutter‘, as it’s a fine application.

So, if you didn’t read the article about finding an application’s PID, helpfully linked again, we can just use ‘pgrep’. If I run the command on my computer, I get:

So we can now see the PID for Shutter easily enough. (There are numerous ways to get an application’s PID. The pgrep application is generally pretty handy.)

The first command we’re going to try is asking the application to quit. We’re sending a command to the application and asking it nicely to die. That’s -15.

Using the PID gathered in the previous command, and knowing the proper syntax for this command, we end up with a command that looks like this:

Of course, sometimes the application doesn’t die when asked nicely. That’s not all that often, but it’s also not all that rare. It does happen and that’s when we skip trying to talk to the application and send a command straight to the kernel. That’d look like this:

That command tells the kernel to drop the application. In theory, this always works. You may still see the process listed in your list of processes but that’s just a zombie process and nothing to be too alarmed with.

You want to first try -15 because that closes the application more gracefully.  When you use -9 as your signal, you’re more or less just using a hammer to kill the process. If -9 doesn’t work, something is up with your kernel and it’s time to reboot. 

NOTE: The commands I used did not include ‘sudo‘. That’s because I owned the processes. If it’s a process owned by someone other than your user, you will need the correct permissions to kill it, such as sudo.

I am not going to cover them here, but you can send all sorts of signals with the kill command – not all of which kill the process. For more information, I highly recommend the following command (and then digging deeper into the rabbit hole):

I suspect you’ll find that to be more than enough information for one day, even though this article hopefully makes it so simple that a beginner can follow along. Hopefully…

Closure:

Well, there you have it. Here’s yet another article and this time we’ve learned how to kill processes by their PID. There’s so much more to this, but those are the basics. You can generally ignore the rest as an average user. You can also probably do a great deal of this with the task manager, all with a nice GUI. It’s worth knowing, and doubly so if you spend any time remotely connected to another device via SSH.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Find An Application’s Process ID (PID)

Today we’re going to have an article that’s straightforward and simple and it will be about how you find an applications’s process ID (PID). This isn’t the article I want to write. This is a case where I have to write one article so that I can write another article. Otherwise, we’d end up with a two-thousand-word article that nobody would read. 

Let’s start with the basics – and it is very, very basic…

Every process running on your Linux computer has a Process ID (PID from here on out). Each process has a unique PID. Curiously, not all PIDs are using resources. Some PIDs are sleeping. If you work at it and find the right dodgy application (I’m looking at you, Shutter), you can even find zombie processes that are darned near impossible to kill (which might be foreshadowing a future article).

Though, unlike the movies, zombie processes are perfectly okay. They just sit there consuming no resources. Plus, they don’t eat brains (or CPU power), nor do they devour human flesh. They don’t even spread to other processes. In fact, with all that information, maybe calling them zombie processes is a bad idea. It’s not my idea – and they do share one thing in common with zombies in that they can’t be killed. (Zombies are already dead. You can’t kill something that’s already dead!)

There are many ways to find the PID for any given process. You can probably crack open your system monitor and find quite a few listed right there. You won’t even need the terminal for that. Imagine that?!?

(Of course, we’ll be finding PIDs in the terminal. It’s just what we do.)

Find An Application’s PID:

Yup. We’ll need an open terminal. Chances are reasonably good that you can just press CTRL + ALT + T and open up a terminal. Give it a shot, if you haven’t already.

The first thing we’re going to do is generate a giant list of running processes. The first column will be who owns the process (not always you) and the second column will be the PID. To generate this giant list, try this command in said terminal:

It’s a pretty big list, isn’t it? Well, let’s use ‘grep’ to narrow that down quite a bit. You can pipe the output from the previous command into grep and that would look like this:

Using Shutter as an example, the command would look like this:

NOTE: You may find that you see multiple PIDs. That’s because there are multiple instances of the application running. 

If you know the name of the process, you can also try pidof (which should also indicate what it does – it tells you the PID of an application).

So, let’s say we wanted to know the PID of bash. That command would look like this:

In my case, I get four different numbers because I have multiple terminals open, each using bash. No, I don’t consider four open terminals to be abnormal. Well, at least it’s fairly normal for me.

Finally, chances are pretty good that you have ‘pgrep’ available. I did a flip through some VMs and it appears to be installed by default on all the distros I checked. You can use pgrep to find a PID. That would look like this:

So, using Shutter as an example again, we’d try something like this:

Now, not all processes seem to want to be listed like this. For example, if you run the ps aux command, you might have seen processes with weird names like this:

You go ahead and put that into pgrep and let me know if it works for you! It doesn’t work here. But, if you tried pgrep gvfs it will spit out some PIDs for you. At that point, you’re officially above my pay grade. I am not sure and I do not know everything. I did some searching, like a good 30 minutes worth of searching, and didn’t find anything conclusive.

If you happen to know what’s going on, let me know in the comments! Someone is always happy to let me know what I missed (and I’m so grateful for that, I really am.) I swear, I learn more from writing these silly things than you learn from reading them.

Closure:

Well, have you ever needed to know the PID? It’s a pretty useful thing to know, which I’ll cover in a future article. I didn’t want to write some giant 2000-word article only to have folks gloss over the important bits. Sure, it’d make a nice segue to the next article, but you know darned well that I’m unlikely to write the articles in order. I get bored easily!

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Find A Program’s PID (Process Identification)

Today’s article is going to tell you how to find a program’s PID. PID stands for “Process Identification” and every running process has one. It’s in numeric format and knowing the PID makes it easy to manage processes. So, today we’ll be covering that. It’s a quick and easy article, useful perhaps for a future article to reference or as just a quick note as a reminder.

We’ll mostly be using a program called ‘pidof’ and you can figure out why it is named what it is pretty easily. It defines itself as:

pidof — find the process ID of a running program.

As we will just be covering general usage, we really won’t have to be all that verbose. There’s a man page for pidof, which you can (and possibly should) reference. The usage we’ll be covering is just that of a lone admin on their bog-standard home computers. If you have anything other than that, you might want to read the man page.

So, with that in mind, let’s learn how to…

Find A Program’s PID:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

With that terminal now open, you can find a program’s PID with the following command:

That should spit it out. It looks like this:

output from pidoff
That’s a nice and easy one!

On the other hand, it can look like this:

pidof chrome browser with a whole lot of tabs open
That’d be the PIDs of Google Chrome when you have a ton of crap open.

Now, you can do a lot with that information – things best suited for another article perhaps. Either way, you’ve learned how to find a program’s PID. It really was that easy! You’re welcome and thanks for reading!

But wait, there’s more! 

I’m not sure where I came across the gem, but it’s pretty awesome. There are some variations (I tried to find my source for this to give credit where credit is due, but it’s out there in a few places – none older than my notes on the matter) but this one is nice and easy.

Ready? Enter this into your terminal:

That should turn your cursor into a cross-hairs. Go ahead and click on an application and then check the output in the terminal. It should, among a few other tidbits of information, help you find a program’s PID with just a simple point and click. (Useful mostly on applications that only have one or two instance running.)

By the way, if you’re looking to find a script’s PID that you have running, you just need to add the -x flag. It’d look like this:

Which is pretty much all a basic home-user is ever going to need to know. Again, check the man page if it’s more complicated than that.

Closure:

Congratulations! You now know how to find a program’s PID. From there you can do stuff like kill it! I’d expect an article in the future that reaches back to this one, using it as a reference, that makes it all come together a little better. Until then…

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Subscribe To Our Newsletter
Get notified when new articles are published! It's free and I won't send you any spam.
Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.