Skip to content

Commit db91d6a

Browse files
committed
cleanup on the monitoring
1 parent b62854c commit db91d6a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

.github/scripts/monitor_slurm_job.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22
# Monitor a SLURM job and stream its output in real-time
33
# Usage: monitor_slurm_job.sh <job_id> <output_file>
44

5-
set -e
5+
set -euo pipefail
6+
7+
# Cleanup handler to prevent orphaned tail processes
8+
cleanup() {
9+
if [ -n "${tail_pid:-}" ]; then
10+
kill "${tail_pid}" 2>/dev/null || true
11+
fi
12+
}
13+
trap cleanup EXIT
614

715
if [ $# -ne 2 ]; then
816
echo "Usage: $0 <job_id> <output_file>"
@@ -96,8 +104,8 @@ if [ -f "$output_file" ]; then
96104
done
97105
fi
98106

99-
# Stop tailing
100-
kill $tail_pid 2>/dev/null || true
107+
# Stop tailing (trap will also handle this on exit)
108+
kill "${tail_pid}" 2>/dev/null || true
101109

102110
echo ""
103111
echo "=== Final output ==="

0 commit comments

Comments
 (0)