Recently Written · git

tmpl

Insanely simple templates

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

Log | Files | Refs


sh/trap/timeout-handler (259 bytes)

1 # Timeout handler
2 timeout_handler() {
3     echo "Operation timed out" >&2
4     <++>
5     exit 1
6 }
7 
8 trap timeout_handler ALRM
9 
10 (sleep <++>; kill -ALRM $$) &
11 alarm_pid=$!
12 
13 # time-sensitive work
14 <++>
15 
16 # Cancel alarm if completed
17 kill $alarm_pid 2>/dev/null || true