Skip to content

Instantly share code, notes, and snippets.

View arouene's full-sized avatar

Aurélien Rouëné arouene

  • Lucca
  • Nantes (France)
View GitHub Profile
@arouene
arouene / signal.go
Last active January 18, 2021 17:39
Signal interruption pattern for Go
func main() {
running := true
// Make a channel the signal handler will subscribe
sigc := make(chan os.Signal, 1)
// Notify will send a sigint or sigterm signal to the
// the previously created channel `sigc`
signal.Notify(sigc, syscall.SIGINT, syscall.SIGTERM)
go func() {
@arouene
arouene / pwatch.sh
Last active September 7, 2022 20:40
Interruptible process watcher
#!/bin/bash
declare -a JOBS
JOBS=("sleep 1" "sleep 2" "sleep 3")
cleanup() {
trap "" SIGTERM
kill 0
wait