-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkill.sh
More file actions
28 lines (27 loc) · 940 Bytes
/
kill.sh
File metadata and controls
28 lines (27 loc) · 940 Bytes
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
#!/bin/zsh
function kill_processes() {
if ! [ -z $PRIV_SMB ]; then
processes=$(lsof $PRIV_MOUNT 2> /dev/null | grep -v PID | awk '{print $2}' | paste -s -d' ')
if ! [ -z "$processes" ]; then bluen List of hanging processes: ; yellowc " $processes"; fi
for p in $processes; do
if [ "$(ps -p $p -o comm= 2> /dev/null)" = "smbd" ]; then
bluen The hanging process is smb daemon. Stopping service...
systemctl stop smb
bluec Done
if eval "kill -0 $p" 2> /dev/null; then
red "Process smbd is resisive. Killing it. (this is an error)"
eval "kill -9 $p"
fi
else
eval "kill -9 $p"
bluen "Killed process $p"
fi
done
else
processes="$(lsof $PRIV_MOUNT 2> /dev/null | grep -v PID | awk '{print $2}')"
if ! [[ -z $processes ]]; then
yellow Killing processes: $processes
echo "$processes" | xargs kill -9
fi
fi
}