You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGSTKFLT, SIGEMT, or SIGSYS signal causes the program to exit with a stack dump.
It is commonly desired to create such a stack dump using a mechanism such as a signal but without exiting. Such thread dumps may be used to investigate hangs or as a rudimentary sampling profiler. Such built-in handlers are common in other languages such as Java (e.g. using SIGQUIT).
One way for a program to handle this requirement is to handle a signal such as SIGUSR1, generate a stack dump by calling pprof.Lookup on the goroutine profile and then write that to a file with Profile.WriteTo.
Alternatively, native debuggers and tools such as pstack may be used but they generally lack the detail of Go stack dumps.
This proposal is for Go to have a built-in signal handler that non-destructively writes a thread dump to stderr in response to a signal such as SIGUSR2. This would be a behavior change that may cause unintended side effects for any programs that already have a SIGUSR2 handler.
The text was updated successfully, but these errors were encountered:
seankhliao
changed the title
Proposal: os/signal: Add a default, non-destructive signal handler that creates a stack dump
proposal: os/signal: Add a default, non-destructive signal handler that creates a stack dump
Dec 12, 2023
seankhliao
changed the title
proposal: os/signal: Add a default, non-destructive signal handler that creates a stack dump
proposal: runtime: Add a default, non-destructive signal handler that creates a stack dump
Dec 12, 2023
seankhliao
changed the title
proposal: runtime: Add a default, non-destructive signal handler that creates a stack dump
proposal: runtime: add a default, non-destructive signal handler that creates a stack dump
Dec 12, 2023
I also think this is fairly simple to implement in a separate package, and one might depend on different conditions for it to trigger. Here we are discussing signal handlers, but maybe someone else wants to create a dump when memory reaches a certain threshold, or some other condition is reached. I like the idea of a general api involving runtime.Stack that is triggered by some custom condition and writes to a io.Writer of choice.
Proposal Details
By default, Go produces a stack dump and exits on various signals:
It is commonly desired to create such a stack dump using a mechanism such as a signal but without exiting. Such thread dumps may be used to investigate hangs or as a rudimentary sampling profiler. Such built-in handlers are common in other languages such as Java (e.g. using
SIGQUIT
).One way for a program to handle this requirement is to handle a signal such as
SIGUSR1
, generate a stack dump by callingpprof.Lookup
on thegoroutine
profile and then write that to a file withProfile.WriteTo
.Alternatively, native debuggers and tools such as
pstack
may be used but they generally lack the detail of Go stack dumps.This proposal is for Go to have a built-in signal handler that non-destructively writes a thread dump to
stderr
in response to a signal such asSIGUSR2
. This would be a behavior change that may cause unintended side effects for any programs that already have aSIGUSR2
handler.The text was updated successfully, but these errors were encountered: