 Hello, and welcome to a video from filmsbychris.com. That's Chris of the K. There's a link in the description to my website. There you can search through all my videos. And if I didn't already say it, I'm Chris with the K. And I do thank you for watching today. Today we're gonna be looking at monitoring CPU usage, which is, you know, simple to do. But we're gonna show you different options. And of course, you know, if you're using a graphical desktop, there's graphical applications but that's kind of unneeded. On almost all Linux systems, you're gonna have the top command. You can run that and it gives you information about processes and you can see some CPU usage there. What's not always installed by default but a program I prefer is H-Top, which is a little more graphical, you know? It gives you a little percentage bars up here and it seems to update every two seconds, although I bet you can change how quickly it does that. But let's say you don't have these applications installed and you're just on a core system and you don't have a CPU monitoring application. Can you still monitor your CPU usage? Yes, again, Linux is a Unix-like operating system and Unix and Unix-like operating systems in general, everything's a file. Your mouse is a file, your hard drive is a file, your keyboard's a file, your CPU is a file and you can get information, all of this stuff, through files. So I'm gonna leave H-Top right in here at the bottom. I'm gonna go to a prompt here at the top and what we're gonna look at is the proc directory. So you will find on your system in the file system a folder called proc. So in your root directory, forward slash proc. And this directory actually has information about running processes and all your hardware, like real-time stuff, these aren't real files that exist whenever you start your system. When things happen, these are like virtual files that are generated, right? And there is one in this directory called CPU Info. So what I can do is use cat. Cat is the command to read what's in that file. So I'll go ahead and real quick, I'll just make this full screen. It gives you a whole bunch of information on what your processor is, how much cache size it has. It also gives you the usage that it's using in megahertz here, but a whole bunch of other information. But let's go ahead and use the grep command. And we're gonna say grep and we're gonna look for CPU M-H-Z. Now it's important you type this just as I did with a capital M-H-Z. When we run that, it gives us our current CPU usage at the moment that we ran that command. If I run it again, it's gonna give us different numbers because my CPU is constantly changing how much is being used. I'll run it again, so there you go. And if I was to come down here, you can see these numbers correspond to these megahertz here. And you can see that I have eight cores and so we have eight output. If you only have four cores, only you only get four things. If you've got dual core, you'll get two outputs. And if you have a single core processor, you'll just get one. But this directory should exist as far as I know on every Linux system because it's part of the kernel, it's put there. So even if you're working on like a router or a modem because those things run Linux and you can get shells on a lot of them, you may not have something like H-Top readily available or even top, but you could get this information. So we're getting it and it's like, okay, that's what's running at that second. We're running it again, so that's what's running at that second. Well, can we get it to constantly update for us? Well, I've talked about in the past, the command watch, which will basically run this command every two seconds by default. We do need to backslash, that's a backslash, not a forward slash, but backslash out these quotation marks. But once we do that, now every two seconds, this is going to update. And you can see that all those constantly changing, it's basically showing you what's down here. They're a little out of sync from each other. Now, let's say we want faster output. Well, what we can do is we can come here and to the watch command dash N and we can give it a number of seconds. So I can say one second, or if I want it to be even faster, I can say 0.1 seconds. So now it should update and run this command every 10th of a second. And there we go. We are getting our processor usage on the screen for all our cores without any special application for it. We're just using watch and grep now. Obviously, to get this like this, you'd have to use the watch command if you don't have the watch command because that may not be on a light system. Of course, you could always just put it in a loop. So I should be able to say while, something like this, I can say do, I'll clear the screen, I'll run that and then I will sleep for 0.1 seconds done. So this you should be able to do on pretty much everything. Grep is like a core tool. It's gonna be on every Linux system you use. So I should be able to do that. And I did something wrong. It's because I don't want to have these backslashed out. That was for the watch command. There we go. And so now I'm getting it again without the watch command. I wanted to show you the watch command because it's a bit more efficient way to do it than a loop. But on a very bare bone system, you can get your CPU usage just with grep and a for loop or a while loop. That's it. I hope you found this useful. I hope you learned some new techniques even if you're not interested in getting your CPU usage. Maybe you learned something about watch. Maybe you just learned about the proc directory for the first time. There's a lot of useful information in the proc directory and information about running processes, your memory usage, everything on your system that's running that has something going on in the proc directory. So maybe poke around in there a little bit. Anyway, I do thank you for watching. Please visit filmsbychrist.com. That's Chris the K. There's a link in the description. You can search through all my videos there. There's also a support section where you can support me through Libre, Pay, PayPal or Patreon. You can become a monthly supporter. That would be great. You get videos early and also can chat with me a little bit more, a little more interaction with me. I do thank you for watching as always. I hope that you have a great day.