2 回答

TA贡献1862条经验 获得超7个赞
接收信号
看一下os/signal包装。
封装信号实现对传入信号的访问。
文档中甚至还有一个例子:
// Set up channel on which to send signal notifications.
// We must use a buffered channel or risk missing the signal
// if we're not ready to receive when the signal is sent.
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill)
// Block until a signal is received.
s := <-c
fmt.Println("Got signal:", s)
发送信号
要了解如何发送信号,请看一看signal_test.go,它使用syscall. 例如 :
// Send this process a SIGHUP
t.Logf("sighup...")
syscall.Kill(syscall.Getpid(), syscall.SIGHUP)
waitSig(t, c, syscall.SIGHUP)

TA贡献1856条经验 获得超17个赞
我发现在 go i 中我们可以将环境传递给 syscall.Exec
err := syscall.Exec(argv0. os.Args. os.Environ())
只需将当前 env 复制到子进程。
- 2 回答
- 0 关注
- 264 浏览
添加回答
举报