Skip to content

Instantly share code, notes, and snippets.

@caruccio
Created December 18, 2022 16:29
Show Gist options
  • Save caruccio/1e7902c730125317e4c9b860e201cd85 to your computer and use it in GitHub Desktop.
Save caruccio/1e7902c730125317e4c9b860e201cd85 to your computer and use it in GitHub Desktop.
Suspend cpu greed process and economize your batery

Create the file stop-proc below:

#!/bin/bash

SIG=${0##*/}    ## basename only (name of the file itself, no dirs)
SIG=${SIG%-*}   ## remove filename suffix. "-*" is a glob pattern ("stop" in this case)
SIG=${SIG^^}    ## UPPERCASE all letters

## read process from command line or use this as default.
## Change it for what you need
[ $# -gt 0 ] && PROCS="$@" || PROCS="brave chrome firefox slack telegram"   

## Replace $1, $2, $N... by the values from $PROCS
set -- $PROCS

## Loop over $1, $2, $N...
for proc; do
    echo pkill -$SIG $proc
    pkill -$SIG $proc
done

Create a symlink for it. The prefix must be the signal you want to send the processes.

ln -s stop-proc cont-proc`

Explanation

Send a SIGSTOP signal for CPU hungry processes like brave/chorme/firefox, slack, telegram, whatever. They will stop being scheduled (just like CTRL-Z in bash/sh). To let them run again, send a SIGCONT (continue).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment