b7a894bac11be1c652debb3e2410dfac431be6ed
kill_unwanted.sh
A bash script that monitors running processes and kills those exceeding configurable CPU, memory, or runtime thresholds.
_ _ _ _ _ _
| | (_) | | | | | |
| | ___| | |_____ _ _ _ ____ ____ _ _ __ | |_ ___ __| |
| |/ / | | |_____| | | | '_ \ \ /\ / / _` | '_ \| __/ _ \/ _` |
| <| | | | | |_| | | | \ V V / (_| | | | | || __/ (_| |
|_|\_\_|_|_| \__,_|_| |_|\_/\_/ \__,_|_| |_|\__\___|\__,_|
Features
- Continuously scans running processes for excessive resource usage
- Configurable thresholds for memory (RAM), CPU utilization, and grace period before action
- Optional graceful termination (
SIGTERM) or hard kill with fallback (SIGTERM→SIGKILL) - Nerd Font icon and colored output support
Usage
./kill_unwanted.sh [OPTIONS]
Options
| Flag | Description | Default |
|---|---|---|
-m, --memory [GiB] |
Maximum allowed RAM usage per process | 32 GiB |
-t, --time [SECONDS] |
Grace period before a process is considered for action | 15 s |
-u, --utilization [PERCENT] |
Maximum allowed CPU usage per process | 50 % |
-r, --refresh [SECONDS] |
Time between rescans | 3 s |
-k, --kill |
Send SIGTERM to offending processes |
— |
--hardkill [SECONDS] |
Send SIGTERM, then SIGKILL after a delay |
10 s |
-n, --nerdfonts |
Enable Nerd Font icons in output | off |
-c, --color |
Enable colored output | off |
--help |
Display the help message and exit | — |
Note: running any flag without a value prints its current configured value instead of setting it.
Examples
# Limit processes to 8 GiB RAM
./kill_unwanted.sh --memory 8
# Kill processes exceeding 10% CPU or 1 GiB RAM, immunity 60s, rescan every 2s, colored output
./kill_unwanted.sh -t 60 -u 10 -m 1 -r 2 -c
# Check current CPU threshold with colored output
./kill_unwanted.sh --utilization -c
# Print memory/CPU thresholds, set refresh to 2s, enable Nerd Fonts + color
./kill_unwanted.sh -m -u -r 2 -n -c
Requirements
- Bash
- Standard Unix process utilities (
ps,kill, etc.)
License
MIT
Languages
Shell
88%
Python
12%