-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os: Interrupt is not sendable on Windows #6720
Labels
ExpertNeeded
FrozenDueToAge
Suggested
Issues that may be good for new contributors looking for work to do.
Comments
There is no such thing as "signal" on windows. You cannot "send a signal to a process". You can only kill process - http://msdn.microsoft.com/en-us/library/windows/desktop/ms686714(v=vs.85).aspx. If you use TerminateProcess API, process that gets killed has no knowledge of the event - it just dies. I don't see how your request can be implemented. Tell me more about your problem. Thank you. Alex |
Owner changed to @alexbrainman. |
The use case is process management. I want to be able to send a signal to another process to tell it to shut itself down gracefully. Its exact implementation on Windows is irrelevant to my use case as long as proc.Signal(os.Interrupt) causes that value to appear via signal.Notify(c, os.Interrupt) in the other process. |
It seems that CTRL_C_EVENTS are handled correctly. You can register for os.Interrupt with signal.Notify and this signal will be delivered when you press CTRL+C in the command prompt. However, it doesn't seem possible to send these events from a program: process.Signal(os.Interrupt) doesn't have any effect on the process being signalled. If it's not possible to achieve this in win32, maybe we need to settle for clarifying the language in http://golang.org/pkg/os/#Signal which implies os.Interrupt and os.Kill will work everywhere. |
djd, I plan to implement process.Signal(os.Interrupt) on windows. In fact we already have something like it already here https://code.google.com/p/go/source/browse/src/pkg/os/signal/signal_windows_test.go#17. After Go 1.2 is released. Alex |
David, Life is never simple. I have a problem (I remember now I was fighting with that test back then too). I am using GenerateConsoleCtrlEvent Windows API (http://msdn.microsoft.com/en-us/library/windows/desktop/ms683155(v=vs.85).aspx). It sends signal to a "console process group". The "console" here is important, I think - it is not about process here, it is about console that group of processes share between them. New process can be started with CREATE_NEW_PROCESS_GROUP flag - from what I can gather, it makes new process use new "console", otherwise it shares it with the parent. If process is started with CREATE_NEW_PROCESS_GROUP flag, it also means new "process group" is created and that group can be referred to by new process id. The GenerateConsoleCtrlEvent has 2 arguments: dwCtrlEvent and dwProcessGroupId. We can supply new pid in dwProcessGroupId, but it will only work, if new process is started with CREATE_NEW_PROCESS_GROUP flag. Alternatively, dwProcessGroupId has to be 0, then the signal is sent to "current process group" - that will send signal to the parent as well as client (it will go to everyone who shares current console). dwCtrlEvent can be CTRL_C_EVENT or CTRL_BREAK_EVENT, but according to the doco CTRL_C_EVENT cannot be used unless dwProcessGroupId is 0. So, the only way to use GenerateConsoleCtrlEvent is with dwCtrlEvent=CTRL_BREAK_EVENT and dwProcessGroupId set to a client process pid that was started with CREATE_NEW_PROCESS_GROUP flag. That is what my test does. Will that suit you? Alex |
Here https://golang.org/cl/29290044, if someone wants to try it. Alex |
From my understanding, making a new console process group also messes up other things. For example, the processes no longer listen to CTRL-C from the console the user invoked the original/parent process in. Maybe the right course here is to document this limitation more clearly: Interrupt doesn't work cleanly in every os. |
> ... For example, the processes no longer listen to CTRL-C from the console the user invoked the original/parent process in. Correct. > ... Maybe the right course here is to document this limitation more clearly: Interrupt doesn't work cleanly in every os. Sounds fine to me. Should I drop my change then? Alex |
The doco: https://golang.org/cl/92340043/ Alex |
CL https://golang.org/cl/92340043 mentions this issue. |
This issue was closed by revision 05cc78d. Status changed to Fixed. |
dsymonds
added
os-windows
ExpertNeeded
Suggested
Issues that may be good for new contributors looking for work to do.
labels
May 23, 2014
wheatman
pushed a commit
to wheatman/go-akaros
that referenced
this issue
Jun 25, 2018
Fixes golang#6720. LGTM=bradfitz R=golang-codereviews, iant, bradfitz CC=golang-codereviews https://golang.org/cl/92340043
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
ExpertNeeded
FrozenDueToAge
Suggested
Issues that may be good for new contributors looking for work to do.
The text was updated successfully, but these errors were encountered: