Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use lscpu | grep 'MHz' to get my clock speed. I am getting different results based on the method I am calling this command.

Method 1: typing it in the terminal
CPU MHz: 1200.000

Method 2: Encapsulating it in a script called
Script code:

#! /bin/bash
cpu=$(lscpu | grep 'MHz')
echo $cpu

Then, in the terminaL

$ chmod +x
$ ./

CPU MHz: 1200.000

So far so good. But now, method 3: hiting the 'run or view current file' in Geany on Output:
CPU MHz: 2200.000

Method 4: writing a python script called that calls
Python script code:

#! /usr/bin/python
import subprocess

def test():"./")

if __name__ == '__main__':

Then, in the terminal:
$ python

CPU MHz: 2200.000

I've tried both python and python3. Both give the same (erroneous) result.

Why does lscpu give a different output when it is run indirectly? And how can I fix this/circumvent this? Is something wrong in my code? For what it's worth, I am running Ubuntu 13.10.

Thanks :-).

share|improve this question
Gx1sptDTDa, good question, thanks. But you should really get a simple name, lol I wonder I spell it correctly here in my comment. – beginer Jul 27 '14 at 9:50
up vote 3 down vote accepted

That's a coincidence, it's your system changing the current cpu frequency.

Check with this command in a terminal:

watch -n 0 "lscpu | grep 'MHz'"

You will see (when waiting a bit) that the system's cpu frequency is switching.

You can also get your current cpu frequency with this command:

cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq

And your maximum/minimum cpu freq with those:

cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq
cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq

Change the behavior? The cpu governor decides what frequency should be used. See this documentation of the linux kernel to decide with cpu governor fits best for you.

  • Get the governor: cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
  • Change the governor: echo "powersave" >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
share|improve this answer
Aha! I guess calling an extra interpreter (in the case of python) requires more work, thus the governor ups the frequency? Makes some sense. – Gx1sptDTDa Apr 8 '14 at 14:03

Most modern CPUs can adjust their clock frequency. The default governor on linux is "on demand" which keeps the clock speed low to save power when idle, and speeds it up to do work when needed.


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.