package main import ( "context" "fmt" "os" "os/exec" "os/signal" "syscall" "time" ) func main() { ctx, cancel := context.WithCancel(context.Background()) defer cancel() signal.NotifyContext(ctx, os.Interrupt, syscall.SIGHUP) cmd := exec.CommandContext(ctx, "sleep", "5") go func() { for { time.Sleep(5 * time.Second) fmt.Println("I'm still alive!") } }() if err := cmd.Start(); err != nil { panic("Error starting command: " + err.Error()) } if err := cmd.Wait(); err != nil { fmt.Printf("Error waiting for command: %v\n", err) } }