Ubuntu – When I lock the PC, the fans get very noisy as if there was some kind of a rogue process

cpu loadgnome-sessiongnome-terminallock-screen

The moment I lock my PC, the fans get really noisy, which means there has to be some kind of CPU/GPU load behind the scenes.

I told myself, I need to know, what process is doing this, so I've crafted this audit script using top and awk, which basically takes *.csv filename as input and writes there every second 10 most demanding processes.

#!/bin/bash

SLEEP_SECS=1

DESTFILE="$1"
if ! [[ "${DESTFILE}" =~ \.csv$ ]]; then
        echo "Please provide name of a destination .csv file!"
        exit 1
fi

if ! test -f "${DESTFILE}"; then
        echo "Seconds;PID;User;% CPU;Process Name" > "${DESTFILE}" || exit $?
fi

while true; do
        top -b -o %CPU -n1 | \
                tail -n +8 | \
                head -10 | \
                awk '{print systime() ";" $1 ";" $2 ";" $9 ";" $12}' \
                >> "${DESTFILE}" || exit $?
        echo -n .
        sleep "${SLEEP_SECS}"
done

So I've started the script and locked my screen, fans got really noisy, I waited a little, logged back in, fans got quiet (as if they knew I don't want them to be noisy when I'm not doing anything with the PC 😀 ) and I've looked into the processes, which got more than 50% of the CPU usage with this command:

gawk --use-lc-numeric -F';' '{if($4 > 50) {print $0}}' cpu-audit.csv

Here's what I've found:

# The header wasn't there OFC, I'm including it just for the convenience
  Seconds ; PID;  User  ;% CPU;Process Name
1566804437;2496;jirislav;106,7;gnome-shell
1566804438;2496;jirislav;106,7;gnome-shell
1566804439;2496;jirislav;100,0;gnome-shell
1566804440;2496;jirislav;100,0;gnome-shell
1566804442;2496;jirislav;93,8;gnome-shell
1566804443;2496;jirislav;100,0;gnome-shell
1566804444;2496;jirislav;100,0;gnome-shell
1566804445;2496;jirislav;100,0;gnome-shell
1566804446;2496;jirislav;106,7;gnome-shell
1566804449;2496;jirislav;131,2;gnome-shell
1566804449;17446;jirislav;68,8;nautilus

What a surprise, gnome-shell was demanding so much resources? What the …?! I'm not even using it, I use terminator all the time. Ok, so I ran the terminal audit using ps, but it haven't detected the usage as the top did, why not? I'm even listing all the child processes:

$ while true; do ps fu --ppid 2496 --pid 2496; sleep 1; done
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
jirislav  2496  7.3  2.2 2949284 357176 tty2   Rl+  08:49   3:02 /usr/bin/gnome-shell
jirislav  2522  0.7  0.0 322108  8800 tty2     Sl   08:49   0:18  \_ ibus-daemon --xim --panel disable
jirislav  3239  1.2  0.4 855328 67956 tty2     Sl+  08:49   0:30  \_ /usr/bin/python3 /usr/bin/terminato
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
jirislav  2496  7.3  2.2 2949284 356820 tty2   Sl+  08:49   3:02 /usr/bin/gnome-shell
jirislav  2522  0.7  0.0 322108  8800 tty2     Sl   08:49   0:18  \_ ibus-daemon --xim --panel disable
jirislav  3239  1.2  0.4 855328 67956 tty2     Sl+  08:49   0:30  \_ /usr/bin/python3 /usr/bin/terminato
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
jirislav  2496  7.3  2.2 2949284 356820 tty2   Rl+  08:49   3:03 /usr/bin/gnome-shell
jirislav  2522  0.7  0.0 322108  8800 tty2     Sl   08:49   0:18  \_ ibus-daemon --xim --panel disable
jirislav  3239  1.2  0.4 855328 67956 tty2     Sl+  08:49   0:30  \_ /usr/bin/python3 /usr/bin/terminato

I said enough, let's uninstall gnome-shell, I'm not even using it, why let it consume the resources and run noisy fans without my consent? .. Then it hit me, gnome-shell cannot be uninstalled without also uninstalling ubuntu-desktop – let's put aside the question why there is this weird dependency, which doesn't make sense (it could use any other terminal) – the thing I'm wandering about is – what is Ubuntu doing while my session is locked and can I turn this off?

When I'm on meeting, it's really inconvenient.

Note:

I know about the question Ubuntu 18.04 gnome-shell high CPU usage, but none of the proposed solutions work (not that I even expected them to work, because the issue is that mine gnome-shell is using too much resources only when I lock the PC – not when I use it as the linked question describes)

Best Answer

  • I had the same problem. Looks like it's a bug with the nVidia driver. The problem vanished after I installed the latest open-source nVidia driver:

    sudo apt install nvidia-driver-455
    
  • Related Question