-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPROCESS-KILLER
57 lines (49 loc) · 1.81 KB
/
PROCESS-KILLER
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# Define ANSI color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Function to display processes
show_processes() {
clear
echo -e "${CYAN}┌───────────────────────────────────────────────────────┐"
echo -e "│ ${YELLOW}Process Killer - Select a process to terminate ${CYAN} │"
echo -e "└───────────────────────────────────────────────────────┘${NC}"
echo ""
# Get processes with PID, CPU%, MEM%, and command
ps -eo pid,pcpu,pmem,comm --sort=-%cpu | awk 'NR<=20' | while read -r pid pcpu pmem comm; do
printf "${GREEN}%6s ${RED}%5s%% ${BLUE}%5s%% ${YELLOW}%-30s${NC}\n" "$pid" "$pcpu" "$pmem" "$comm"
done
}
while true; do
show_processes
echo -e "\n${CYAN}Enter PID to kill (or 'q' to quit, 'r' to refresh):${NC} "
read -r choice
# Exit if user chooses q
if [[ "$choice" == "q" ]]; then
echo -e "${RED}Exiting.${NC}"
break
fi
# Refresh if user chooses r
if [[ "$choice" == "r" ]]; then
continue
fi
# Check if input is numeric
if [[ "$choice" =~ ^[0-9]+$ ]]; then
# Verify process exists
if ps -p "$choice" > /dev/null; then
echo -e "${YELLOW}Killing process ${RED}$choice${YELLOW}...${NC}"
kill -9 "$choice"
sleep 1
else
echo -e "${RED}No process with PID $choice found!${NC}"
sleep 1
fi
else
echo -e "${RED}Invalid input. Please enter a numeric PID.${NC}"
sleep 1
fi
done