github.com/vlifesystems/rulehunter@v0.0.0-20180501090014-673078aa4a83/cmd/interrupt_windows_test.go (about)

     1  package cmd
     2  
     3  import (
     4  	"os"
     5  	"syscall"
     6  	"testing"
     7  )
     8  
     9  func interruptProcess(t *testing.T) {
    10  	dll, err := syscall.LoadDLL("kernel32.dll")
    11  	if err != nil {
    12  		t.Fatalf("LoadDLL(\"kernel32.dll\") err: %s", err)
    13  	}
    14  	p, err := dll.FindProc("GenerateConsoleCtrlEvent")
    15  	if err != nil {
    16  		t.Fatalf("FindProc(\"GenerateConsoleCtrlEvent\") err: %s", err)
    17  	}
    18  	// Send the CTRL_BREAK_EVENT to a console process group that shares
    19  	// the console associated with the calling process.
    20  	// https://msdn.microsoft.com/en-us/library/windows/desktop/ms683155(v=vs.85).aspx
    21  	pid := os.Getpid()
    22  	r1, _, err := p.Call(syscall.CTRL_BREAK_EVENT, uintptr(pid))
    23  	if r1 == 0 {
    24  		t.Fatalf("Call(CTRL_BREAK_EVENT, %d) err: %s", pid, err)
    25  	}
    26  }