Pimaxin
Posts: 75
Joined: Sat Jan 19, 2019 7:34 pm

[ubuntu] Getting CPU tempature on Ubuntu

Thu Sep 19, 2019 1:32 am

I have Ubuntu installed on my Raspberry Pi 4 and was wondering if there's a way to run vcgencmd or get the CPU tempature?

mallets
Posts: 4
Joined: Thu Sep 19, 2019 4:00 am

Re: Getting CPU tempature on Ubuntu

Thu Sep 19, 2019 4:02 am

Code: Select all

cat /sys/class/thermal/thermal_zone0/temp
works for me. I'm still searching for the CPU freq value though.

Pimaxin
Posts: 75
Joined: Sat Jan 19, 2019 7:34 pm

Re: Getting CPU tempature on Ubuntu

Thu Sep 19, 2019 9:17 am

mallets wrote:
Thu Sep 19, 2019 4:02 am

Code: Select all

cat /sys/class/thermal/thermal_zone0/temp
works for me. I'm still searching for the CPU freq value though.
What’s 38459 supposed to mean?

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 26442
Joined: Sat Jul 30, 2011 7:41 pm

Re: Getting CPU tempature on Ubuntu

Thu Sep 19, 2019 9:31 am

Pimaxin wrote:
Thu Sep 19, 2019 9:17 am
mallets wrote:
Thu Sep 19, 2019 4:02 am

Code: Select all

cat /sys/class/thermal/thermal_zone0/temp
works for me. I'm still searching for the CPU freq value though.
What’s 38459 supposed to mean?
It's a prime number!
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

Heater
Posts: 15838
Joined: Tue Jul 17, 2012 3:02 pm

Re: Getting CPU tempature on Ubuntu

Thu Sep 19, 2019 9:42 am

The successor to 38458.
Memory in C++ is a leaky abstraction .

Heater
Posts: 15838
Joined: Tue Jul 17, 2012 3:02 pm

Re: [ubuntu] Getting CPU tempature on Ubuntu

Thu Sep 19, 2019 10:30 am

A clue for American viewers. It works in Centigrade.
Memory in C++ is a leaky abstraction .

User avatar
rpdom
Posts: 17029
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Getting CPU tempature on Ubuntu

Thu Sep 19, 2019 10:32 am

Pimaxin wrote:
Thu Sep 19, 2019 9:17 am
mallets wrote:
Thu Sep 19, 2019 4:02 am

Code: Select all

cat /sys/class/thermal/thermal_zone0/temp
works for me. I'm still searching for the CPU freq value though.
What’s 38459 supposed to mean?
If that is the value returned from that command for you, it means your CPU temperature is currently 38.459°C
Unreadable squiggle

User avatar
DougieLawson
Posts: 38883
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: [ubuntu] Getting CPU tempature on Ubuntu

Thu Sep 19, 2019 10:34 am

Take the prime number divide by 1000, multiply by 1.8 and add 32. You'l then get the temperature on the scale of that really bad physicist Mr. F.

I'm surprised nobody has suggested getting the userland (https://GitHub.com/raspberrypi/userland) pieces installed on Ubuntu. To add some of the missing pieces.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Heater
Posts: 15838
Joined: Tue Jul 17, 2012 3:02 pm

Re: [ubuntu] Getting CPU tempature on Ubuntu

Thu Sep 19, 2019 11:56 am

Now, now, you can't go round calling members of the FRS "bad physisists".

Physics did not exist back then. Guys like Mr F. invented it for us.

Rock bands and authors have been celebrating his name for ages: https://en.wikipedia.org/wiki/Fahrenhei ... biguation)
Memory in C++ is a leaky abstraction .

User avatar
BluPI2
Posts: 52
Joined: Sun May 10, 2015 3:56 am
Location: United States

Re: [ubuntu] Getting CPU tempature on Ubuntu

Sun Sep 22, 2019 5:40 am

There is a nice way to add this to the taskbar in Ubuntu

Steps
1. Right-click taskbar and click +add to panel

2. Scroll down and Highlight Command(Shows the output of a command), Click Add

3. Right-click the newly added widget, click preferences, and set interval seconds to 5
and max character width to 2. Copy and Paste this command into the Command Box

Code: Select all

cat /sys/class/thermal/thermal_zone0/temp
You now get the temperature displayed in your taskbar which updates every 5 seconds displayed in Celsius.

Even in the United States we still use Centigrade to measure the temperature of a CPU.
Proud Owner of a Raspberry Pi 3B and 3B+ running Ubuntu Mate

aduen
Posts: 1
Joined: Tue May 05, 2020 11:33 am

Re: [ubuntu] Getting CPU tempature on Ubuntu

Tue May 05, 2020 11:50 am

For the bash aficionados:

Code: Select all

#!/bin/bash

temp=$(</sys/class/thermal/thermal_zone0/temp)

temp_f=`echo "$temp/1000" | bc -l`
printf "CPU Temp: %.3f°C\n"  $temp_f
>> CPU Temp: 40.407°C

aturfer
Posts: 5
Joined: Sat Feb 25, 2012 7:50 pm

Re: [ubuntu] Getting CPU tempature on Ubuntu

Sat Jun 06, 2020 11:12 pm

For those who feel like compiling something, create file temp.c with the following:

Code: Select all

#include <stdio.h>

int main(int argc, char *argv[]) 
{
   FILE *fp;

   int temp = 0;
   fp = fopen("/sys/class/thermal/thermal_zone0/temp", "r");
   fscanf(fp, "%d", &temp);
   printf(">> CPU Temp: %.2f°C\n", temp / 1000.0);
   fclose(fp);

   return 0;
}
Compile with:

Code: Select all

$ gcc temp.c -o temp
Then copy to directory in your path:

Code: Select all

$ sudo mv ./temp /usr/local/bin/
Run from anywhere:

Code: Select all

aturfer@pi4:~$ temp
>> CPU Temp: 42.35°C

aturfer
Posts: 5
Joined: Sat Feb 25, 2012 7:50 pm

Re: Getting CPU tempature on Ubuntu

Sat Jun 06, 2020 11:44 pm

mallets wrote:
Thu Sep 19, 2019 4:02 am
I'm still searching for the CPU freq value though.

Current CPU frequency:

Code: Select all

echo ">> CPU Freq:" $(($(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq)/1000))MHz

To get min/max CPU frequency range:

Code: Select all

lscpu | grep -i mhz

saikiran91
Posts: 1
Joined: Sat Jul 04, 2020 1:32 pm

Re: [ubuntu] Getting CPU tempature on Ubuntu

Sat Jul 04, 2020 1:34 pm

aturfer wrote:
Sat Jun 06, 2020 11:12 pm
For those who feel like compiling something, create file temp.c with the following:

Code: Select all

#include <stdio.h>

int main(int argc, char *argv[]) 
{
   FILE *fp;

   int temp = 0;
   fp = fopen("/sys/class/thermal/thermal_zone0/temp", "r");
   fscanf(fp, "%d", &temp);
   printf(">> CPU Temp: %.2f°C\n", temp / 1000.0);
   fclose(fp);

   return 0;
}
Compile with:

Code: Select all

$ gcc temp.c -o temp
Then copy to directory in your path:

Code: Select all

$ sudo mv ./temp /usr/local/bin/
Run from anywhere:

Code: Select all

aturfer@pi4:~$ temp
>> CPU Temp: 42.35°C
Simple and sexy. One more request how can we get a continuous updates.

Return to “Ubuntu”