Proposal Details
By default, Go produces a stack dump and exits on various signals:
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.
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.Lookupon thegoroutineprofile and then write that to a file withProfile.WriteTo.Alternatively, native debuggers and tools such as
pstackmay 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
stderrin response to a signal such asSIGUSR2. This would be a behavior change that may cause unintended side effects for any programs that already have aSIGUSR2handler.