ubuntu go进程信号

package main
import (
"fmt"
"os"
"os/signal"
"time"
)
func main() {
go signalListen()
for {
time.Sleep(10 * time.Second)
}
}
func signalListen() {
c := make(chan os.Signal)
signal.Notify(c)
for {
s := <-c
fmt.Println("get signal:", s)
}
}

ctrl+c: ^Cget signal: interrupt

docker-compose down, docker stop: get signal: terminated

kill -9 pidofproc: 不会产生信号

// Signals
const (
SIGABRT = Signal(0x6)
SIGALRM = Signal(0xe)
SIGBUS = Signal(0x7)
SIGCHLD = Signal(0x11)
SIGCLD = Signal(0x11)
SIGCONT = Signal(0x12)
SIGFPE = Signal(0x8)
SIGHUP = Signal(0x1)
SIGILL = Signal(0x4)
SIGINT = Signal(0x2)
SIGIO = Signal(0x1d)
SIGIOT = Signal(0x6)
SIGKILL = Signal(0x9)
SIGPIPE = Signal(0xd)
SIGPOLL = Signal(0x1d)
SIGPROF = Signal(0x1b)
SIGPWR = Signal(0x1e)
SIGQUIT = Signal(0x3)
SIGSEGV = Signal(0xb)
SIGSTKFLT = Signal(0x10)
SIGSTOP = Signal(0x13)
SIGSYS = Signal(0x1f)
SIGTERM = Signal(0xf)
SIGTRAP = Signal(0x5)
SIGTSTP = Signal(0x14)
SIGTTIN = Signal(0x15)
SIGTTOU = Signal(0x16)
SIGUNUSED = Signal(0x1f)
SIGURG = Signal(0x17)
SIGUSR1 = Signal(0xa)
SIGUSR2 = Signal(0xc)
SIGVTALRM = Signal(0x1a)
SIGWINCH = Signal(0x1c)
SIGXCPU = Signal(0x18)
SIGXFSZ = Signal(0x19)
)

// Signal table

var signals = [...]string{
1: "hangup",
2: "interrupt",
3: "quit",
4: "illegal instruction",
5: "trace/breakpoint trap",
6: "aborted",
7: "bus error",
8: "floating point exception",
9: "killed",
10: "user defined signal 1",
11: "segmentation fault",
12: "user defined signal 2",
13: "broken pipe",
14: "alarm clock",
15: "terminated",
16: "stack fault",
17: "child exited",
18: "continued",
19: "stopped (signal)",
20: "stopped",
21: "stopped (tty input)",
22: "stopped (tty output)",
23: "urgent I/O condition",
24: "CPU time limit exceeded",
25: "file size limit exceeded",
26: "virtual timer expired",
27: "profiling timer expired",
28: "window changed",
29: "I/O possible",
30: "power failure",
31: "bad system call",
}

 

posted on 2021-08-31 15:00  csuyangpeng  阅读(91)  评论(0编辑  收藏  举报

导航

//替换成自己路径的js文件