#!/bin/bash
sv_stop() {
for s in $(ls -d /etc/service/*)
do
/sbin/sv stop $s
done
}
trap "" SIGCHLD
trap "sv_stop; exit" SIGTERM
/sbin/runsvdir /etc/service &
wait
By setting handler for SIGCHLD to explicit ignore, POSIX.1-2001 allows a parent process to elect for the kernel to automatically reap child processes that terminate. trap "" SIGCHLD is the same as explicitly setting SIGCHLD handler to SIG_IGN. This is untested though. I am not sure if one can really trap SIGCHLD in bash.
Wouldn't this work:
By setting handler for SIGCHLD to explicit ignore, POSIX.1-2001 allows a parent process to elect for the kernel to automatically reap child processes that terminate.
trap "" SIGCHLD
is the same as explicitly setting SIGCHLD handler to SIG_IGN. This is untested though. I am not sure if one can really trap SIGCHLD in bash.Also see the script here. But I do think it has an issue.