Skip to content

Add cross-platform interrupt signal utility #726

@dogancanbakir

Description

@dogancanbakir

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 GenerateConsoleCtrlEvent via 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.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions