Get list of goroutines and their stack trace

6,889 views
Skip to first unread message

Daniel Huckstep

unread,
Dec 22, 2011, 11:11:13 PM12/22/11
to golan...@googlegroups.com
Is there a way to get a list of running goroutines along with stack trace information? I can't see anything in the docs, so I'm assuming no.

I'd like to see what's running so I can debug goroutines that may be leaking or just be running for longer that I believe they should be (even if they aren't leaked).

This also got me thinking thinking about some sort of runtime "plugin" system. Maybe as a core feature this ability to get at goroutines isn't a good idea, but if there were some way to poke inside the runtime with a C plugin, then the plugin could supply this functionality. Then you can load it to do your debugging, and remove it afterwards (probably not while the program is running....but maybe...).

I'm just thinking out loud. The main thing is getting that list of goroutines with stacks.

Thoughts?

--
Daniel Huckstep

Russ Cox

unread,
Dec 22, 2011, 11:15:26 PM12/22/11
to golan...@googlegroups.com
It's not possible now, sorry. This is http://golang.org/issue/2516.
It's definitely something we want to support in the future.

Russ

Daniel Huckstep

unread,
Dec 22, 2011, 11:22:18 PM12/22/11
to golan...@googlegroups.com, r...@golang.org
Thanks for the quick response Russ! I've starred the issue to keep an eye on it.

- Daniel

Kyle Lemons

unread,
Dec 27, 2011, 4:08:11 PM12/27/11
to golan...@googlegroups.com
SIGQUIT (^\) does this for me; of course, it also kills the program. 

Daniel Huckstep

unread,
Dec 28, 2011, 10:10:18 PM12/28/11
to golan...@googlegroups.com
I wonder if forking the process and immediately QUIT or ABRT (I think ABRT does the same thing) it and capturing the output would be feasible. Kind of the-worst-way-to-possibly-do-it, but hey!

- Daniel

Kevin

unread,
Jan 11, 2012, 12:58:29 AM1/11/12
to golang-nuts
If there's more than one thread (almost assuredly the case if you have
multiple goroutines), then this won't work, since the fork syscall
explicitly is documented as creating a child with only the thread that
called fork.

On Dec 28 2011, 8:10 pm, Daniel Huckstep

Dmitry Vyukov

unread,
Jan 11, 2012, 9:50:32 AM1/11/12
to Kevin, golang-nuts
On Wed, Jan 11, 2012 at 9:58 AM, Kevin <extempor...@gmail.com> wrote:
If there's more than one thread (almost assuredly the case if you have
multiple goroutines), then this won't work, since the fork syscall
explicitly is documented as creating a child with only the thread that
called fork.

One thread will be able to dump stacks of all goroutines.

zupah...@gmail.com

unread,
Aug 23, 2015, 5:35:52 AM8/23/15
to golang-nuts
Ah thanks Kyle a 1000x you saved my day! :)

Tieson Molly

unread,
Aug 25, 2015, 2:48:19 PM8/25/15
to golang-nuts, darkh...@darkhelmetlive.com
Could you just use something like

http://stackoverflow.com/questions/19094099/how-to-dump-goroutine-stacktraces

but instead of SIGQUIT,  use SIGUSR1

I do something like this in Perl where I define a signal handler that will dump a stack trace to stdout and then just continue running.

Reply all
Reply to author
Forward
0 new messages