go func() { ticker := time.NewTicker(15 * time.Minute) defer ticker.Stop() for { <-ticker.C printGoroutines() } }() func printGoroutines() { const initSize = 64 * 1024 // Initial buffer size (64KB) buf := make([]byte, initSize) for { n := runtime.Stack(buf, true) if n < len(buf) { os.Stdout.Write([]byte("Goroutine list:\n")) os.Stdout.Write(buf[:n]) os.Stdout.Write([]byte("\n")) return } // Buffer was too small; double it and try again buf = make([]byte, 2*len(buf)) } }