Created
May 24, 2024 19:11
-
-
Save naranyala/34e529aed0b4878b8facd2479359b041 to your computer and use it in GitHub Desktop.
your cpu eater solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Get the top ten processes consuming the most CPU | |
top_processes=$(ps -eo pid,comm,%cpu --sort=-%cpu | head -n 11 | tail -n 10) | |
# Format the process list for rofi | |
process_list=$(echo "$top_processes" | awk '{print $1 " " $2 " (" $3 "%)"}') | |
# Show the process list in rofi and get the user's choice | |
chosen=$(echo "$process_list" | rofi -dmenu -p "Kill Process:") | |
# Extract the PID from the chosen line | |
pid=$(echo "$chosen" | awk '{print $1}') | |
# Prompt for the sudo password using rofi | |
password=$(rofi -dmenu -password -p "Enter sudo password:") | |
# Confirm and kill the selected process using sudo | |
if [ -n "$pid" ] && [ -n "$password" ]; then | |
echo "$password" | sudo -S kill -9 $pid | |
if [ $? -eq 0 ]; then | |
notify-send "Process $pid has been killed." | |
else | |
notify-send "Failed to kill process $pid." | |
fi | |
else | |
notify-send "No process selected or no password entered." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment