Skip to content

os, os/signal: inconsistent documentation #27854

@kevinburke

Description

@kevinburke

I'm trying to define cleanup behavior in a Windows program, so I want to catch a signal, do some cleanup, and then exit the program. I don't have a Windows machine though so testing this is sort of tricky.

The docs for os.Interrupt state:

The only signal values guaranteed to be present in the os package on all systems are Interrupt (send the process an interrupt) and Kill (force the process to exit). Interrupt is not implemented on Windows; using it with os.Process.Signal will return an error.

However, the docs for os/signal state, under the Windows section:

On Windows a ^C (Control-C) or ^BREAK (Control-Break) normally cause the program to exit. If Notify is called for os.Interrupt, ^C or ^BREAK will cause os.Interrupt to be sent on the channel, and the program will not exit.

I'm confused how Interrupt can be all of:

  • guaranteed to be present
  • not implemented
  • calling Notify() can cause it to be sent on the channel when a user hits ^BREAK

Searching the os package source code for Interrupt seems to show it's only defined for unix/posix GOOS's and not for Windows. It might be nice to add a short doc to the os package explaining how it gets sent (if I am reading correctly, from runtime/os_windows.go:ctrlhandler1 and runtime/sigqueue.go:sigsend).

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.OS-Windows

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions