-
Notifications
You must be signed in to change notification settings - Fork 0
/
testOS_Signal.go
47 lines (41 loc) · 870 Bytes
/
testOS_Signal.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
)
func main() {
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, os.Kill, syscall.SIGTERM)
c := make(chan int, 1)
arr := []int{1, 2}
// Running the HTTP server
go func() {
for _, i := range arr {
time.Sleep(time.Duration(i) * time.Second)
fmt.Printf("Number %d \n", i)
}
os.Exit(0)
// time.Sleep(10 * time.Second)
// c <- 500
}()
interruptSignal := <-interrupt
switch interruptSignal {
case os.Kill:
fmt.Println("Got SIGKILL...")
c <- 100
case os.Interrupt:
fmt.Println("Got SIGINT...")
//time.Sleep(4 * time.Second)
c <- 400
case syscall.SIGTERM:
fmt.Println("Got SIGTERM...")
c <- 700
}
fmt.Println("The service is shutting down...")
//server.Shutdown(context.Background())
x := <-c
fmt.Println("Shut down is done", x)
}