Stopping the fans with a script

19 Nov, 2019
0 views
unix

I find it irritating when fans on my laptop start spinning out of control, especially if it’s caused by something non-critical or running in the background.

I caught myself going to htop regularly in order to find out what process is slamming the CPU and then SIGKILL it by pressing F9 and then 9.

That’s why I decided to write a script that just kills the relevant process and therefore silences the fans. No htop necessary.

#! /usr/bin/env bash
# Silences the fans of your computer. Kills processes
# which use more than threshold percent
# of your CPU.
# The default threshold, processes using more than
# this percentage of the CPU will be killed with
# SIGKILL.
threshold=90
# List PID, CPU percentage and command name.
ps -eo pid,%cpu,args |
 # Filter processes that are above the threshold.
 awk -v threshold=$threshold '{if(2ドル==2ドル+0 && 2ドル > threshold) print 1ドル " " 3ドル}' |
 # Sort by CPU usage to kill the worst offenders first.
 sort -n |
 # # Kill the passed process and report it being killed.
 xargs -L1 bash -c 'kill -9 0ドル && printf "killed: 1ドル\n"'

Put it in your $PATH and call it with

$ silencio

In order to go full Harry Potter on your fans.

AltStyle によって変換されたページ (->オリジナル) /