This is Hacker Public Radio episode 3,746 from Monday 12th of December 2022. Today's show is entitled CPU Info. It is hosted by Klottu and is about 15 minutes long. It carries a clean flag. The summary is, how to get CPU Info on Linux? Hey everybody, how do you get information about your CPU on Linux anyway? Well, actually there are a couple of different ways, as it turns out, and I kind of got curious recently of all of the different ways. Can't guarantee that I've found all of the different ways. Here are some that I've run across, which some of these are going to know off the top of your head as well. But the first one, I guess, is maybe the most obvious, possibly it's you name. You name can process a bunch of different information about really your system. And I think a lot of us use just uname-a, or uname-a, kind of by habit. The dash a is really dash dash all, uname dash dash all. That prints everything that uname has access to all most. The v is, what is the v? V actually isn't any, oh no, it is kernel version. That's what it is. Current kernel version. Okay, so that's a uname-a v. And that gives you a lot of information. I mean, like dash dash all dash dash kernel dash version. That gives you that your own Linux. It gives you your host name. It gives you the kernel version, whether it's an SMP, kernel or not, pre-empt is active or not, the date that that kernel was compiled on. And then the architecture, X86 under Square 64 in my case, and then the CPU vinder ID, AMD, Ryzen 5 5 6 0s or X and then some details about that. That's not the vinder ID. Is it that's like the model or something. The vinder ID is authentic AMD I think. So that's a lot of information from uname-a v. So what you can also do is, according to man uname. the dash i or dash dash hardware dash platform. So if I do that you name dash dash hardware dash platform, then I get authentic AMD returned. There's also the dash p which dash dash processor. That's going to give you the processor type. You name dash dash processor AMD Ryzen 5, 5600x, 6 core processor. That's what it says. And then finally there's dash m or dash dash machine which provides the architecture. So you name space dash dash machine in my case returns x86 underscore 64. That's that's the architecture of that CPU. Okay, so interestingly, there's another tool called arch. And that's also distributed within the GNU core utiles package. And it does exactly I think one thing. And that is returns the architecture of the machine you are running on. So it is exactly like you name dash dash machine except it's a different command called arch. So type in ARCH into your terminal, hit return and you get what architecture you're running again on this current machine that I'm recording this episode on and typing stuff into a terminal on x86 underscore 64. So it's u name and then ARCH. And then the other way that I could think of to get this kind of information and I'm assuming I haven't actually looked at the source code of u name or ARCH. So this is where it's getting the information from. It's the virtual file system under slash prock slash CPU info. If you do a cat on that, you get all kinds of information about every single different core on your machine. So that's probably overkill. You're probably going to want to type it through grep for it to be very effective. But the kind of information you're getting is the vendor underscore ID. So that's authentic AMD in my case model space name AMD Ryzen blah blah blah. So that's it for the slash prock CPU info. At least I poked around and prock a little bit more and couldn't find anything directly related to it. I did find some other things that I'll get to in a moment. But first before I go into the absurd, I want to go to the more practical, which are the desktop applications that you might use to find out this kind of information. And this could be useful, you know, when you're when you're helping, I mean, they could be useful in general. I use K and Fist Center all the time. I love that application. But it can also be a really useful way to help someone else get the information that maybe you need in order to support them better. So KDE, the KDE desktop provides K info center. It is a system summary application. It pops up all the information about your system with information about the kernel that you're running, the hardware that you're running it on, the amount of memory that you have, the energy consumption or available, whatever it's called, RAM and so on. So it's very useful. It's kind of, I guess, a front end technically to a solid KDE solid. So that also means that you can get CPU information. And there's a lot of information about that actually on in the devices section. But the general overview, the quick, just like after you've launched K info center, the first thing that you see there is a system summary. And it may not immediately be obvious where the architecture information is. But it just so happens. At least on my systems, it says kernel version. And then after the kernel version, it gives you that it's a 64-bit processor or 32-bit processor. Or rather, it tells you whether you're running a 64-bit kernel or a 32-bit kernel. So that is there on the main screen. You can also go down to devices and go down to, in the left column, CPU. And that gives you a pretty good representation, I think, of, well, really most of the stuff out of Slash Proc. But it also, right up at the top, it says architecture x86, underscore 64, CPU op modes, 32-bit comma 64-bit. So it tells you of quite a lot of information about just sort of how you're able to use that CPU. Of course, I'm just, I'm being very biased here towards like x86, not because I want to be biased by it. But that's just the computer that I'm on right now, and that I've kind of poked around long enough to do this. The same kind of information would be available on a pi, of course, but you're going to see different, different sort of output, and I'll go over that in a moment as well. So then the genome version of this information is in settings. The application is just called settings and go down all the way to the bottom of the list about on the left, and sort of near the bottom of the resulting list, you can find the, what they, what they call is the OS type, and that'll tell you whether it's 64-bit, 32-bit, whatever. So that's the genome version of K InfoCenter. Now, on some other architecture, I mean, really all the same things apply. It's not really that different. I mean, you've got a name, a, you name dash a for dash dash all for all of the information about your kernel, which by default does include the architecture. So for the, on this Raspberry Pi 4, a arch 64, there it is. You could do, you name dash m for just the a arch 64. You can do a you name dash i for a arch 64, you name dash p for a arch 64. Pretty consistent to be honest. Arch returns a arch 64, and then, of course, cat CPU info gives you a lot of the information that I've already talked about, including the hardware version, which is listed as vcm 2835, and the model, which is listed as Raspberry Pi 4, model b rev, one dot four in this particular instance. And, and then, so I couldn't find any other tools really. I mean, there, you know, there are half a dozen tools out there that'll just query slash prox slash CPU info. So just going over everyone could be, get a little bit redundant. But it occurred to me that there got to be other things you could query to get this kind of information. I didn't do a whole lot of looking around. I did find some C++ boost libraries that have, well, it's the architecture series, if you look in boost. And it's a bunch of header files in there that can, that that provide a bunch of data about what architecture it is running on. And that that seems really, really useful. But I'm assuming once again, if you're, if you're at the point of dropping down to writing code to try to figure out whether you're at 32 bit or 64 bit system, you probably don't have boost installed. It's probably not even safe to say that you have C++ installed. And yet that's what I'm going to assume. So if you do something like a hash include left angle bracket, IO stream, right angle bracket, that that just gives you C out. I mean, you could do without it. You could just, you could just dump straight to standard out. But I'm just taking a shortcut and using C out. So using namespace standard semi colon and then int main parentheses parentheses, curly brace, C out, no, not yet. Let's do if, if parentheses size underscore max. And size underscore max is a, you have to have C++ like 11 or greater installed. But I think that's relatively, if we're saying you have C++, you probably have a recent dish version of C++, maybe. So size underscore max tells you the maximum value of the of of what a variable can hold. Like what the maximum value integer size of a variable can be. So size underscore max, that's all capitals equals equals zero X F F F F F F F closed parentheses curly brace, C out left or, what is it? Yeah, left angle bracket left angle bracket, quote, I don't know, 32 bit close, quote, semi colon. And then you do it close the curly brace else space if parentheses size underscore max equals equals zero X F F F F F F F F F F F F F F F F F F F F F F F F F F F Close parentheses curly brace, C out left angle bracket left angle bracket, quote, 64 bit closed quotes semi colon. And then just in case I guess curly brace else curly Brace and then see out left angle bracket link left angle bracket quote I don't know close quote semi colon curly close curly brace returns you're a semi colon and then close curly brace and then if I do a G plus plus CPU arch dot CPP is what I call this dash O CPU arch that seemed to compile and then I hit return and yeah I get 64 bit it's right before my prompt because I didn't put the left you know the back slash in or in the L if I wanted to forgot that but that's fine so 64 bit here and then if I run that on on Raspberry Pi of course actually I'm not gonna go to the trouble I did it before it would return a arch 64 or rather it would detect that it was 64 you know this is just a test literally 32 bit 64 but it's not telling you the actual architecture it's not saying whether it's an X86 or a risk or an you know arm or whatever I guess arm technically is risk but you know what I'm saying it doesn't tell you the the architecture so much as it does the bitidness it's probably a better more official term for that of the CPU so this is just a simple example of of querying data that maybe you know indicates to you the thing that you want to know if you're not able to get to the actual thing that you want to know just an interesting exercise and I'll leave it up to you to think of other ways to do it because I didn't put a whole lot of thought into this to be honest and like I say lots of other languages or I guess arguably I put too much thought into this and this is where I am now but I didn't I didn't go into depth in the in like okay what kind of code could be right because obviously there are existing libraries that actually do this already a lot better anyway so it's not that useful it's just I think the exercise was interesting because it forced me to think around the problem and get to a solution through a different avenue than I would have initially thought so those are the different ways I personally can think of to get the architect the the the kind of CPU that's powering the system that you are on I don't know when that would be useful I mean it might be useful a lot there are lots of lots of other different ways I'm sure of getting this information like I said there are probably well there are definitely a bunch of other commands that will query slash prox slash CPU info there are programming libraries that are aware of the hardware underneath them after you compile them or if they're you know interpreted languages then they probably already have access to that data so there's a lot there you could also just query the file system you know like looking user share or or slash var slash something or another and see see if there are files there that betray as it were the the architecture that that things have been installed for so that's yet another way think of some more ways it's a fun exercise actually and also kind of useful because people do need to know this kind of information they do sometimes need to know what kind of CPU they're running and if they've listened to this episode then they know how to find it in a couple of different ways thanks for listening talk to you next time you have been listening to hacker public radio as hacker public radio does a book today show was contributed by a hbware listener like yourself if you ever thought of a coin podcast click on our contribute link to find out how easy it means hosting price we are has been kindly provided by an onsthost.com the internet archive and our sing.net on this otherwise stages they show is released on our creative comments attribution for pointo international license