A Go process is running. I want to
You can set up a handler like that using code something like this:
import (
"fmt"
"os"
"os/signal"
"runtime"
"syscall"
)
func main() {
sigChan := make(chan os.Signal)
go func() {
stacktrace := make([]byte, 8192)
for _ = range sigChan {
length := runtime.Stack(stacktrace, true)
fmt.Println(string(stacktrace[:length]))
}
}()
signal.Notify(sigChan, syscall.SIGQUIT)
...
}
The SIGQUIT
signal will now be caught and sent to the given channel. The runtime.Stack
function is then used to format the stack trace into a prepared buffer (if it is larger than the buffer, it will be truncated), and then printed.