Whether we’re using aRaspberry Pior a data center server, we need to know how our CPU and RAM are performing and, in Linux, there are a plethora of commands and applications that we can use. At the basic low level “How much RAM have I used?” to inspecting the CPU for vulnerabilities such as Spectre, there are commands at our disposal.
We are going to look at a number of different ways to get RAM and CPU data in the terminal, before we finally look at two applications which can provide a basic level of assurance, at a glance.
These commands will work on most Linux machines. Our test PC is running Kubuntu, the KDE flavor of Ubuntu, but we also certain that you can also run through this how-to on aRaspberry Pior any other Linux device.All of the how-to is performed via the Terminal.
2.Use the cat command to display the data held in/proc/cpuinfo.
This command will produce a lot of text, typically it will repeat the same information for the number of cores present in your CPU.
A more concise means to get most of this information is vialscpu, a command that lists the CPU details.
Get Tom’s Hardware’s best news and in-depth reviews, straight to your inbox.
1.Open a terminal.
2.Uselscputo display the CPU details.The command is quite verbose and we can easily see the number of CPU cores, minimum and maximum CPU speed and the CPU architecture.
Using a littlegrepmagic we can pull out just the information that we need.
2.Using a vertical pipe, send the output of thelscpucommand togrepand search for “max”.This will give us the maximum possible CPU speed. Pipes are a way to send the output of one command as the input for another. Classic examples are piping the output of a command to a text file for later review.
Another means to get CPU information is usingdmidecode, a command that dumps the DMI (SMBIOS) contents into something we can understand.
2.Type in thedmidecodecommandusing sudo, and the argument-t 4.There are many DMI types, with a numerical reference used to pull information for that component. In this case-t 4is for the CPU. We can replace the 4 withprocessorfor the same effect.
How to Check Your RAM in Linux
1.Open a terminal window.
2.Use thefreecommand.This will show the available memory, and how the memory has been allocated, in Kilobytes.
3.Use the-mswitchto show the available memory in Megabytes, or-gfor Gigabytes.
Alternatively use the-hswitchto show the memory information scaled to the three shortest digits. Giving us at a glance information.
There is a similar way to /proc/cpuinfo for memory information.
2.Use thecatcommand to print the contents of/proc/meminfo.The output is incredibly verbose and can prove useful for debug. In general use we would stick withfree -m.
If we need to know the timings and breakdown of memory modules in a machine then we can uselshw.
2.Using sudo, issue thelshwcommandwith the-shortswitch (the device tree) and-Cwith the classmemory.
Information at a Glance
Should we need a more general level of information, our current CPU speed, RAM usage, network bandwidth then we have two commands which can be installed.
How to Install and Use Htop
The standardtopcommand is great, but htop is a much better alternative. Htop provides us with an interactive list of running processes.
4.Runhtop.
At the top of the window we can see the utilization of our CPU cores, under that is our RAM, and finally is the swap.
We can scroll through the list with our cursor keys or search using F3 followed by the name of a process or application. Here we have searched for the GNU Image Manipulation Program (GIMP). We can kill the app by pressing F9.
How to Install and Use Bpytop
Our personal preference is bpytop, a Python implementation of htop but with much more to offer.
- CPU StatusCPU SpeedCore utilizationOverall utilization
2. RAM UsageTotal RAMUsed RAMAvailable RAMCache
Disk / Storage UsageUsed and free space on all mounted devices
Network Interface UsageUp and down speeds
- Processes (just like htop)Process management
We can show or hide an area by pressing the corresponding number (1..4). If we just wanted CPU, RAM, storage and Network information then we press 4. To bring it back, press 4 again.
1.Press f to filter.It has to be lower case f.
2.Type in the application / process name / Pid.The search will adapt to show the process, in our case GIMP.
3.Press T to terminate the process, or K to kill.These have to be upper case T and K.
To exit bpytoppress q at any time.
Les Pounder is an associate editor at Tom’s Hardware. He is a creative technologist and for seven years has created projects to educate and inspire minds both young and old. He has worked with the Raspberry Pi Foundation to write and deliver their teacher training program “Picademy”.