Skip to content
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

How to determine that the program will be stopped? #115

Closed
heretic13 opened this issue May 29, 2016 · 3 comments · Fixed by #487 or #580
Closed

How to determine that the program will be stopped? #115

heretic13 opened this issue May 29, 2016 · 3 comments · Fixed by #487 or #580
Milestone

Comments

@heretic13
Copy link

heretic13 commented May 29, 2016

Hello.

There is a console program. How do I intercept the event of closure and perform some action on the freeing of resources?

Interception SIGINT does not work.

Messages from log:
2016-05-29 11:27:56 - Send SIGINT 8368
2016-05-29 11:27:56 - SIGINT to 8368 failed - Killing as fallback

I think problem in 'AttachConsole'.

OS: Windows 10 x64

@heretic13
Copy link
Author

heretic13 commented May 29, 2016

Relly simple code in go to test it


package main

import (
"fmt"
"os"
"os/signal"
)

func main() {
// Set up channel on which to send signal notifications.
// We must use a buffered channel or risk missing the signal
// if we're not ready to receive when the signal is sent.
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
// Block until a signal is received.
s := <-c
fmt.Println("Got signal:", s)
}


It works when yourself push Ctrl-C, but I do not see a message about closing when working through the wrapper

@heretic13
Copy link
Author

heretic13 commented May 29, 2016

Modify program


package main

import (
"fmt"
"io/ioutil"
"os"
"os/signal"
)

func main() {
fmt.Println("hello")
// Set up channel on which to send signal notifications.
// We must use a buffered channel or risk missing the signal
// if we're not ready to receive when the signal is sent.
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
// Block until a signal is received.
s := <-c
fmt.Println("Got signal:", s)
d1 := []byte("hello\ngo\n")
ioutil.WriteFile("dat1", d1, 0644)
}


File not created at service stop.

@oleg-nenashev
Copy link
Member

Most likely it's a Windows service specifics.
Need to RTFM about the signal handling behavior in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants