go获取协程(goroutine)号

func GetGID() uint64 {
       b := make([]byte, 64)
       b = b[:runtime.Stack(b, false)]
       b = bytes.TrimPrefix(b, []byte("goroutine "))
       b = b[:bytes.IndexByte(b, ' ')]
       n, _ := strconv.ParseUint(string(b), 10, 64)
       return n
}

你可能感兴趣的:(go)