tl;dt https://github.com/nozo-moto/signal_kansitai
A little research, I wanted to know what kind of signal was sent to the application
Go language can handle when there is a signal in the created goroutine by doing the following.
c := make(chan os.Signal)
signal.Notify(c)
go func() {
for {
s := <-c
log.Println("signal :", s)
}
}
}()
Good logging I wanted to write to standard output and log file, so I used ʻio.MultiWriter`
logfile, err := os.OpenFile("./signal.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
if err != nil {
panic("cannnot create log :" + err.Error())
}
defer logfile.Close()
log.SetOutput(io.MultiWriter(logfile, os.Stdout))
log.SetFlags(log.Ldate | log.Ltime)
It handles the signal like this and sends it
% tail -f signal.log
2020/02/09 21:48:01 alive :
2020/02/09 21:49:01 alive :
2020/02/09 21:50:01 alive :
2020/02/09 21:50:33 signal : hangup false
I tried to drop it when SIGTERM was sent. Survival is confirmed once every 60 seconds. Also, systems that cannot be handled, such as SIGKILL, cannot be handled and die.
I found out that there is a signal to change the window size of the terminal called SIGWINCH.
Recommended Posts