fix dev_run.sh not stopping child processes on Ctrl-C
run_with_label piped output through a while loop, so $! tracked the formatter PID instead of the actual command. Ctrl-C killed the formatters but left app/worker/css-watch running as orphans. Switch to process substitution so $! is the real command PID, and pkill -P children before killing tracked PIDs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -71,6 +71,8 @@ cleanup() {
|
|||||||
echo ""
|
echo ""
|
||||||
echo -e "${BOLD}Stopping all processes...${NC}"
|
echo -e "${BOLD}Stopping all processes...${NC}"
|
||||||
for pid in "${PIDS[@]}"; do
|
for pid in "${PIDS[@]}"; do
|
||||||
|
# Kill children first (e.g. make → tailwind), then the process itself
|
||||||
|
pkill -P "$pid" 2>/dev/null || true
|
||||||
kill "$pid" 2>/dev/null || true
|
kill "$pid" 2>/dev/null || true
|
||||||
done
|
done
|
||||||
wait 2>/dev/null || true
|
wait 2>/dev/null || true
|
||||||
@@ -81,12 +83,11 @@ cleanup() {
|
|||||||
trap cleanup SIGINT SIGTERM
|
trap cleanup SIGINT SIGTERM
|
||||||
|
|
||||||
# Prefix each line of a command's output with a colored label.
|
# Prefix each line of a command's output with a colored label.
|
||||||
|
# Uses process substitution so $! is the actual command PID (not the formatter).
|
||||||
run_with_label() {
|
run_with_label() {
|
||||||
local color="$1" label="$2"
|
local color="$1" label="$2"
|
||||||
shift 2
|
shift 2
|
||||||
"$@" 2>&1 | while IFS= read -r line; do
|
"$@" > >(while IFS= read -r line; do echo -e "${color}[${label}]${NC} ${line}"; done) 2>&1 &
|
||||||
echo -e "${color}[${label}]${NC} ${line}"
|
|
||||||
done &
|
|
||||||
PIDS+=($!)
|
PIDS+=($!)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user