duadlkc5762218 2018-08-31 01:40
浏览 626
已采纳

外部程序可以知道go程序中goroutine的数量吗?

I can get the value through this "runtime.NumGoroutine()"..

Can I know the number of goroutines in an external program?

  • 写回答

1条回答 默认 最新

  • dongzhuan1185 2018-08-31 05:44
    关注

    Maybe you can use delve.

    1. go get github.com/derekparker/delve/cmd/dlv
    2. run your main application
    3. find the $pid of your main applicaiton
    4. dlv attach $pid, then type goroutines to see all go routines like follows:
    C:\work\gowork>dlv attach 5696
    Type 'help' for list of commands.
    (dlv) goroutines
    [5 goroutines]
      Goroutine 1 - User: C:/devsoft/Go/src/runtime/time.go:102 time.Sleep (0x440c3b)
      Goroutine 2 - User: C:/devsoft/Go/src/runtime/proc.go:292 runtime.gopark (0x42a03f)
      Goroutine 3 - User: C:/devsoft/Go/src/runtime/proc.go:292 runtime.gopark (0x42a03f)
      Goroutine 17 - User: C:/devsoft/Go/src/runtime/proc.go:292 runtime.gopark (0x42a03f)
    * Goroutine 19 - User: :0 ??? (0x7fffef855427) (thread 15260)
    (dlv)
    

    Then, what your program needs to do is to control the command dlv using something like expect to control the debug tool to input goroutines command.

    Seems it has a xml-rpc like api for client to get more infomation, you may can have a look, I did not use the api before.

    Just a thought, FYI.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办