-
Notifications
You must be signed in to change notification settings - Fork 10
/
nix.sh
executable file
·50 lines (41 loc) · 1.1 KB
/
nix.sh
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
#!/bin/bash
# ANSI escape codes for coloring output
RED='\033[0;31m'
NC='\033[0m' # No Color
# Get all PIDs
all_pids=$(ps -e -o pid=)
# Initialize counts
all_count=0
nix_count=0
# Loop over all PIDs
for pid in $all_pids; do
# Skip if the process is this script itself
if [ $pid -eq $$ ]; then
continue
fi
# Get full path of process
full_path=$(readlink -f /proc/$pid/exe 2>/dev/null)
# Only count processes with a path
if [[ -n $full_path ]]; then
# Increment total count
((all_count++))
# Check if it starts with /nix
if [[ $full_path == /nix* ]]; then
# Increment nix count
((nix_count++))
# Print in red
echo -e "${RED}Nix process found: $full_path${NC}"
else
# Print in normal color
echo "Process: $full_path"
fi
fi
done
# Calculate the ratio
if [ "$all_count" -gt 0 ]; then
ratio=$(echo "scale=2; $nix_count / $all_count" | bc)
else
ratio=0
fi
echo "Number of /nix processes: $nix_count"
echo "Ratio of /nix processes to all processes: $ratio"