-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions
50 lines (42 loc) · 1.25 KB
/
functions
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
eval "$(fasd --init auto)"
killp() {
pid=$(lsof -t -i:$1)
if [ -z "$pid" ]; then
echo "No process is using port $1"
return 1
fi
kill -15 $pid # send SIGTERM
echo -n "Sent SIGTERM to process $pid, waiting for it to exit"
# Wait for up to 5 seconds, checking each second
for i in {1..10}; do
if ! kill -0 $pid 2>/dev/null; then
echo -e "\nProcess exited gracefully within $i second(s)."
return 0
fi
echo -n "."
sleep 1
done
echo ""
# Check if the process is still running after 5 seconds
if kill -0 $pid 2>/dev/null; then
echo "Process did not terminate within 5 seconds, sending SIGKILL..."
kill -9 $pid
echo "Process was killed forcefully with SIGKILL"
else
echo "Process was killed gracefully with SIGTERM"
fi
}
reload_bluetooth_module() {
echo "Unloading Bluetooth module..."
sudo modprobe -r btusb
echo "Bluetooth module unloaded."
echo "Restarting Bluetooth service..."
sudo systemctl restart bluetooth
echo "Bluetooth service restarted."
echo "Reloading Bluetooth module..."
sudo modprobe btusb
echo "Bluetooth module reloaded."
}
function h() {
distrobox-host-exec "$@"
}