Skip to content

Instantly share code, notes, and snippets.

@patricksuo
Last active November 12, 2018 03:38
Show Gist options
  • Save patricksuo/85754e12634adeab6b4a5b157cad8a83 to your computer and use it in GitHub Desktop.
Save patricksuo/85754e12634adeab6b4a5b157cad8a83 to your computer and use it in GitHub Desktop.
PID
// gist 不支持空文件
package pid
import (
_ "unsafe"
)
//go:linkname ProcPin runtime.procPin
func ProcPin() int
//go:linkname ProcUnpin runtime.procUnpin
func ProcUnpin()
package pid
import (
"fmt"
"testing"
)
func TestPid(t *testing.T) {
id := ProcPin()
fmt.Printf("pid:%d", id)
ProcUnpin()
}
func BenchmarkPid(b *testing.B) {
for i := 0; i < b.N; i++ {
ProcPin()
ProcUnpin()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment