From 49d75e223eded02597b7a45d877bc7001d4d66f0 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Fri, 3 Nov 2017 23:51:39 -0500 Subject: [PATCH] use os.Process#Kill (Fixes #73) --- common/os.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/common/os.go b/common/os.go index 81f703c7d..36fc969fa 100644 --- a/common/os.go +++ b/common/os.go @@ -35,6 +35,8 @@ func GoPath() string { return path } +// TrapSignal catches the SIGTERM and executes cb function. After that it exits +// with code 1. func TrapSignal(cb func()) { c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt, syscall.SIGTERM) @@ -50,10 +52,13 @@ func TrapSignal(cb func()) { select {} } -// Kill the running process by sending itself SIGTERM +// Kill the running process by sending itself SIGTERM. func Kill() error { - pid := os.Getpid() - return syscall.Kill(pid, syscall.SIGTERM) + p, err := os.FindProcess(os.Getpid()) + if err != nil { + return err + } + return p.Signal(syscall.SIGTERM) } func Exit(s string) {