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 關注
- 286 瀏覽
添加回答
舉報