-
Notifications
You must be signed in to change notification settings - Fork 43
Open
Labels
Type: EnhancementMost issues will probably ask for additions or changes.Most issues will probably ask for additions or changes.
Description
Summary
Add a utility function to send interrupt signals to processes in a cross-platform way.
Background
Currently implemented in goflags (projectdiscovery/goflags#241) for the --max-time feature. This functionality could be useful for other tools.
Current Implementation
Unix (interrupt_unix.go):
func sendInterrupt() {
if p, err := os.FindProcess(os.Getpid()); err == nil {
_ = p.Signal(os.Interrupt)
}
}Windows (interrupt_windows.go):
var (
kernel32 = syscall.NewLazyDLL("kernel32.dll")
procGenerateConsoleCtrlEvent = kernel32.NewProc("GenerateConsoleCtrlEvent")
)
func sendInterrupt() {
// CTRL_BREAK_EVENT = 1
procGenerateConsoleCtrlEvent.Call(1, 0)
}Proposed Location
github.com/projectdiscovery/utils/process or new github.com/projectdiscovery/utils/signal package
Why
- Go's
p.Signal(os.Interrupt)is not implemented on Windows - Windows requires
GenerateConsoleCtrlEventvia kernel32.dll - Multiple tools may need this for graceful shutdown features
References
Metadata
Metadata
Assignees
Labels
Type: EnhancementMost issues will probably ask for additions or changes.Most issues will probably ask for additions or changes.