Skip to content

Instantly share code, notes, and snippets.

@naranyala
Created May 24, 2024 19:10
Show Gist options
  • Save naranyala/8b07046476f121ce3b6a70ef013b747a to your computer and use it in GitHub Desktop.
Save naranyala/8b07046476f121ce3b6a70ef013b747a to your computer and use it in GitHub Desktop.
your ram eater solution
#!/bin/bash
# Get the top ten processes consuming the most memory
top_processes=$(ps -eo pid,comm,%mem --sort=-%mem | 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