 Hello everyone. Welcome back to another Linux video. In today's video, we'll be taking a look at four ways, four unique ways we can kill a process in Linux. Now, the first thing that you're going to want to do is install htop. I have it already installed on my system. If you don't have it, you can do sort of app install htop. So once you have that installed, let's take a look at the first way we can kill a process. And my dummy process is going to be just the Chromium web browser. Okay, so I'm going to start off with the most traditional way we can kill a process in Linux and that is using the kill command. And to use the kill command, we first have to find out the process ID of the particular program that we're going to kill the PID in short. So there are a myriad of ways we can find out the PID of a program. In this case, our Chromium web browser here. But I'm just going to use the easiest way in this video. And that is using htop. So let's launch htop here and use f3 to search for the process Chromium. And you can see that on the leftmost column of htop, we have PID, which is a process ID. And that's going to be the PID that I'm going to use later on. But let me first introduce you to the command, the kill command. So the syntax is kill space dash and the termination signal and the process ID. In this case, our Chromium process ID, let me search that up again. I lost it. Chromium will be 22851. So I'm just going to key in 22851. And there are a lot of different termination signals that you can use. I'm just going to use dash 9 for now. If you want to find out the list of termination signals, you can do something like man kill. And you can look up all of the numbers in here. I'll just use 9 in this case. That should work most of the time. So I'm just going to hit enter. Wait, hang on. Let me have Chromium up here first and the terminal on my left. And I'm just going to hit enter. And you can see the Chromium web browser is just gone. So that is our first most traditional way to kill a program. Moving on, we have our next command, which is kill all. Now, in case you didn't notice, previously when we were using the kill command, we had to specify the process ID specifically of that particular process that we want to kill. And sometimes it's just a bit of a hassle because we have to go find out the name of the process. And then after that, we're going to find out what's the number of the process. Only then we can use the kill command. Instead, if you use kill all, we'll be able to kill all processes that matches a particular string pattern. And let me show you right here if I go htop. This time, I'm going to start htop with the dash D argument because I want refresh rate to be a bit longer so we can see what's going on here. Now I have a Chromium web browser instance running here. And if I search for Chromium, you'll be able to see that I have at least two different entries of Chromium. And then I have a third here. And then I might have a fourth somewhere else. And there's just a lot of entries of Chromium. And there are different process IDs for those different entries in htop. And with kill all, we can just specify the string pattern that we want to kill. And it's just going to kill all of the processes with that string in it. So let's say I type kill all dash nine and Chromium. And before I hit enter, I'm just going to split the screen for now. And if I hit enter, you'll see that the Chromium window is just gone. And if I come to htop and I search for Chromium, we'll see that nothing is found. And so all of the Chromium processes have been terminated by the kill all command. Okay, so that's the kill all command. But before we move on to the next kill command, I want to let all of you know of one small quirk that the kill all command has. And that is the name of the process that is specified to kill has to match up exactly with the actual name of the process itself. Now, if I hit kill all dash nine, and instead of writing the actual Chromium word out itself, I'm just going to leave out this the M at the back and hit enter. And it's just going to say no process found. You have to actually type in letter by letter exactly as the process's name is. So I'm just going to hit and now you can see it works as before. The next command that we're going to look at is called pkill. Okay, so pkill is quite an interesting little kill command. Now, if you don't know, there's another command called pgrab. And so what pgrab does is it outputs all of the process IDs of the processes that matches your search string. So let's say I type chromium in pgrab, it's going to echo all of the process IDs of the processes that have chromium in its name. And that relates back to pkill. So if we type pkill chromium, it's going to kill all of the processes with chromium in its name with this search string at the back in its name. So before that, let me go into split screen once again. And we're going to kill this poor web browser instance here. And then when I hit enter, you can see chromium is just gone. The difference between pkill and killall is that pkill will just destroy all of the processes that have the search string in their name. So if I hit pkill chromium again, this time let me launch that poor browser one more time. And then compared to killall, in killall, if you did kill all chromium without the M, it's not going to kill chromium because there's no process called chromium. So pkill works differently. If I hit enter right now, as you can see, the chromium is just gone. It doesn't care if the search string matches the process label letter by letter. It just kills all chromium instances that has this pattern pattern in the label of the process. And this is a bit more convenient, because if you don't really know the actual name of the process letter by letter, you just know parts of it, then you'll still be able to kill that process. However, that convenience doesn't come without a cost. So if I have chromium, the web browser open up here, and I also have a game called chromium BSU, which is an open source game, quite a fun arcade game here. Open as well. They both have chromium in their name. However, if I launch htop here and let me do a filter, you see chromium BSU is chromium BSU. Chromium is just chromium. So if I do killall chromium, it'll just kill chromium. It won't kill chromium BSU. But if I do pkill chromium, it'll kill both chromium web browser and chromium BSU the game. So that's a bit more dangerous than killall command. That's the pkill command. Up till now, I've shown you a lot of ways you can terminate a process, but there is still one more thing. There's this command called xkill, and it's kind of my favorite because it's just so fun. So let's say you have a buggy program. Say I have a program up and running here and it's unresponsive. It doesn't react to my clicks. I can't close it with the x button. It just doesn't work anymore. So you can hit xkill and hit enter, and you can see that my cursor instantly transforms into this cross. And I can just hover over this barrier window and just click on it, and it's just forced shutdown. It's just terminated. So if there are any programs of yours that are hanging and not listening to commands, you can just do xkill and just kill it off your computer. That concludes all of the ways that I wanted to show you to kill a process. Hopefully it was interesting. I'll see you again next time.