Last active
November 12, 2018 03:38
-
-
Save patricksuo/85754e12634adeab6b4a5b157cad8a83 to your computer and use it in GitHub Desktop.
PID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gist 不支持空文件 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package pid | |
import ( | |
_ "unsafe" | |
) | |
//go:linkname ProcPin runtime.procPin | |
func ProcPin() int | |
//go:linkname ProcUnpin runtime.procUnpin | |
func ProcUnpin() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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