https://github.com/iwdgo/sigintwindows
Sending ctrl-break to a sub-process on Windows to trigger graceful exit.
https://github.com/iwdgo/sigintwindows
golang sigint signal windows
Last synced: 6 months ago
JSON representation
Sending ctrl-break to a sub-process on Windows to trigger graceful exit.
- Host: GitHub
- URL: https://github.com/iwdgo/sigintwindows
- Owner: iwdgo
- License: bsd-3-clause
- Created: 2020-07-04T15:34:02.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-07-05T06:17:42.000Z (about 2 years ago)
- Last Synced: 2025-07-22T04:50:38.655Z (12 months ago)
- Topics: golang, sigint, signal, windows
- Language: Go
- Homepage:
- Size: 25.4 KB
- Stars: 2
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://pkg.go.dev/github.com/iwdgo/sigintwindows)
[](https://goreportcard.com/report/github.com/iwdgo/sigintwindows)
[](https://codecov.io/gh/iwdgo/sigintwindows)
[](https://github.com/iwdgo/sigintwindows/actions/workflows/go.yml)
# On Windows, sends a ctrl-break to a process
## How to
### Experiment
```
$ go get -d github.com/iwdgo/sigintwindows
$ cd
$ go test -v
=== RUN TestSendCtrlBreak
signal_windows_test.go:40: waiting 5 seconds before goroutine. No log to find.
signal_windows_test.go:43: waiting 5 seconds in goroutine. Log displays unless interrupted.
2021/09/22 10:39:38 sub-process 55536 started
2021/09/22 10:39:48 graceful exit on interrupt
--- PASS: TestSendCtrlBreak (15.38s)
PASS
```
The output of the sub-process is in the `ctrlbreak.log` file.
Typing Ctrl-C should display error ` exit status 0xc000013a `
Exit code `0xC000013A` is the exit value `STATUS_CONTROL_C_EXIT` returned by the signal package.
[NTSTATUS](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/596a1078-e883-4972-9bbc-49e60bebca55) says:
> {Application Exit by CTRL+C} The application terminated as a result of a CTRL+C.
### Use as a module
```
import "github.com/iwdgo/sigintwindows"
sigintwindows.SendCtrlBreak()
```
## Online
### Stackoverflow
https://stackoverflow.com/questions/45309984/signal-other-than-sigkill-not-terminating-process-on-windows
https://stackoverflow.com/questions/55092139/gracefully-terminate-a-process-on-windows
### Golang
[golang/go#29744](https://github.com/golang/go/issues/29744)
[golang/go#42311](https://github.com/golang/go/issues/42311)
[golang/go#46354](https://github.com/golang/go/issues/46354)
### About Ctrl-Break on Windows
https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/596a1078-e883-4972-9bbc-49e60bebca55
https://docs.microsoft.com/en-us/windows/console/generateconsolectrlevent
https://docs.microsoft.com/en-us/windows/console/ctrl-c-and-ctrl-break-signals
https://docs.microsoft.com/en-us/windows/win32/procthread/process-creation-flags
### Version history
`v0.2.2` Importable module
`v0.1.0` Standalone experiment
Standalone version of the test `TestCtrlBreak` of the `signal` package of golang.