#!/bin/bash -e

# 查找并杀死由launch.sh启动的进程
# 假设launch.sh启动的进程包含特定的标识符，比如mission名称

# 定义进程标识符（根据实际launch.sh启动的程序进行调整）
#!/bin/bash -e

# Kill all processes launched by launch.sh

echo "Killing AUV150 mission processes..."

# Kill processes by name patterns
pkill -f "pAntler.*targ_vehicle.moos" 2>/dev/null || true
pkill -f "uMAC.*targ_vehicle.moos" 2>/dev/null || true
pkill -f "pNodeReporter" 2>/dev/null || true
pkill -f "uProcessWatch" 2>/dev/null || true
pkill -f "pHelmIvP" 2>/dev/null || true
pkill -f "pAUV150" 2>/dev/null || true
pkill -f "pShare" 2>/dev/null || true
pkill -f "pMarineViewer" 2>/dev/null || true
pkill -f "MOOSDB" 2>/dev/null || true

# Wait a moment for processes to terminate
echo "Waiting for processes to terminate..."
sleep 2

# Force kill any remaining processes
pkill -9 -f "pAntler.*targ_vehicle.moos" 2>/dev/null || true
pkill -9 -f "uMAC.*targ_vehicle.moos" 2>/dev/null || true
pkill -9 -f "pNodeReporter" 2>/dev/null || true
pkill -9 -f "uProcessWatch" 2>/dev/null || true
pkill -9 -f "pHelmIvP" 2>/dev/null || true
pkill -9 -f "pAUV150" 2>/dev/null || true
pkill -9 -f "pShare" 2>/dev/null || true
pkill -9 -f "pMarineViewer" 2>/dev/null || true
pkill -9 -f "MOOSDB" 2>/dev/null || true

echo "All AUV150 processes have been terminated."