Skip to content

Instantly share code, notes, and snippets.

@onemouth
Last active September 22, 2019 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onemouth/b7b0a40de9092a21cb8fa854c8e8d089 to your computer and use it in GitHub Desktop.
Save onemouth/b7b0a40de9092a21cb8fa854c8e8d089 to your computer and use it in GitHub Desktop.
get mcount from go
package main
import (
"C"
"fmt"
"runtime"
"runtime/debug"
"time"
"os/exec"
_ "unsafe"
)
//go:linkname mcount runtime.mcount
func mcount() int32
func getGOMAXPROCS() int {
return runtime.GOMAXPROCS(0)
}
func main() {
//runtime.GOMAXPROCS(20)
fmt.Printf("GOMAXPROCS is %d\n", getGOMAXPROCS())
debug.SetMaxThreads(50)
go func() {
for {
cnt := mcount()
fmt.Println(cnt)
time.Sleep(time.Second)
}
}()
for i := 0; i < 100; i++ {
go func() {
cmd := exec.Command("sleep", "600")
if err := cmd.Run(); err != nil {
fmt.Println(err)
}
}()
time.Sleep(time.Second)
}
c := make(chan int)
<-c
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment