-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkill_remap.sh
More file actions
102 lines (87 loc) · 2.06 KB
/
Copy pathkill_remap.sh
File metadata and controls
102 lines (87 loc) · 2.06 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
set -u
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SELF_PID="$$"
PARENT_PID="${PPID:-}"
echo "Killing ReMap processes..."
declare -a PATTERNS=(
"ReMap-GUI.py"
"desktop_backend.py"
"remap_server.py"
"sfm_runner.py"
"stray_to_colmap.py"
"remap-desktop"
"vite"
"tauri"
)
declare -a EXTERNAL_NAMES=(
"glomap"
"colmap"
"ffmpeg"
)
collect_pids() {
local pattern="$1"
pgrep -f "$pattern" 2>/dev/null || true
}
collect_names() {
local name="$1"
pgrep -x "$name" 2>/dev/null || true
}
collect_children() {
local parent="$1"
local children
children="$(pgrep -P "$parent" 2>/dev/null || true)"
if [ -z "$children" ]; then
return
fi
echo "$children"
while IFS= read -r child; do
[ -n "$child" ] && collect_children "$child"
done <<< "$children"
}
build_target_list() {
{
for pattern in "${PATTERNS[@]}"; do
collect_pids "$pattern"
done
for name in "${EXTERNAL_NAMES[@]}"; do
collect_names "$name"
done
} |
awk -v self="$SELF_PID" -v parent="$PARENT_PID" '
$1 ~ /^[0-9]+$/ && $1 != self && $1 != parent { print $1 }
' |
sort -u
}
TARGETS="$(build_target_list)"
if [ -n "$TARGETS" ]; then
DESCENDANTS="$(
while IFS= read -r pid; do
[ -n "$pid" ] && collect_children "$pid"
done <<< "$TARGETS"
)"
TARGETS="$(printf "%s\n%s\n" "$TARGETS" "$DESCENDANTS" | awk 'NF' | sort -rn | uniq)"
fi
if [ -z "$TARGETS" ]; then
echo "No ReMap processes were running."
exit 0
fi
while IFS= read -r pid; do
[ -n "$pid" ] && kill -TERM "$pid" 2>/dev/null || true
done <<< "$TARGETS"
sleep 0.8
REMAINING="$(build_target_list)"
if [ -n "$REMAINING" ]; then
while IFS= read -r pid; do
[ -n "$pid" ] && kill -KILL "$pid" 2>/dev/null || true
done <<< "$REMAINING"
sleep 0.4
fi
REMAINING="$(build_target_list)"
if [ -n "$REMAINING" ]; then
echo "Some ReMap processes are still running:"
REMAINING_CSV="$(printf "%s\n" "$REMAINING" | paste -sd, -)"
ps -p "$REMAINING_CSV" -o pid=,ppid=,comm=,args=
exit 1
fi
echo "All ReMap processes have been terminated."