Skip to content

Commit 0b0bc04

Browse files
author
hero
committed
添加signal
1 parent 59eab42 commit 0b0bc04

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package tool
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"os/signal"
7+
"syscall"
8+
)
9+
10+
func QuitSignal(quitFunc func()) {
11+
c := make(chan os.Signal, 1)
12+
signal.Notify(c, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
13+
fmt.Printf("server start success pid:%d\n", os.Getpid())
14+
for s := range c {
15+
switch s {
16+
case syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT:
17+
quitFunc()
18+
return
19+
default:
20+
return
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)