Recently Written · git

tmpl

Insanely simple templates

git clone https://github.com/equwal/tmpl

Log | Files | Refs


sh/trap/background-jobs (325 bytes)

1 # Clean up background jobs
2 cleanup_jobs() {
3     # POSIX-compliant version: jobs -p might not exist, and xargs -r is GNU-specific
4     for pid in $(jobs -p 2>/dev/null || true); do
5         kill "$pid" 2>/dev/null || true
6     done
7     wait
8 }
9 trap cleanup_jobs EXIT TERM INT
10 
11 # Start background processes
12 <++> &
13 
14 # carry on
15 <++>