Skip to content

Instantly share code, notes, and snippets.

@vaskoz
Created January 22, 2015 19:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vaskoz/46cf1973a8d4b5945dc7 to your computer and use it in GitHub Desktop.
Save vaskoz/46cf1973a8d4b5945dc7 to your computer and use it in GitHub Desktop.
Golang CPU bomb - actually prevents the main thread from getting scheduled to run
package main
import (
"fmt"
"os"
"os/signal"
"runtime"
"syscall"
)
func main() {
numOfProcessors := runtime.NumCPU()
runtime.GOMAXPROCS(numOfProcessors)
for i := 0; i < numOfProcessors; i++ {
go func() {
for {
}
}()
}
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL)
sig := <-sigChan
fmt.Println(sig)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment