go - Is it possible to capture a Ctrl+C signal and run a cleanup function, in a "defer" fashion? -
i want capture ctrl+c (sigint
) signal sent console , print out partial run totals.
is possible in golang?
note: when first posted question confused ctrl+c being sigterm
instead of sigint
.
you can use os/signal package handle incoming signals. ^c sigint, can use trap os.interrupt
.
c := make(chan os.signal, 1) signal.notify(c, os.interrupt) go func(){ sig := range c { // sig ^c, handle } }()
the manner in cause program terminate , print information entirely you.
Comments
Post a Comment