2017-11-01 19:37:53 -04:00
|
|
|
// +build linux freebsd darwin
|
2016-03-18 14:50:19 -04:00
|
|
|
|
2016-12-12 03:28:41 -05:00
|
|
|
package system
|
2016-03-18 14:50:19 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
2017-05-23 10:22:32 -04:00
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
2016-03-18 14:50:19 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// IsProcessAlive returns true if process with a given pid is running.
|
|
|
|
func IsProcessAlive(pid int) bool {
|
2017-05-23 10:22:32 -04:00
|
|
|
err := unix.Kill(pid, syscall.Signal(0))
|
|
|
|
if err == nil || err == unix.EPERM {
|
2016-03-18 14:50:19 -04:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// KillProcess force-stops a process.
|
|
|
|
func KillProcess(pid int) {
|
2017-05-23 10:22:32 -04:00
|
|
|
unix.Kill(pid, unix.SIGKILL)
|
2016-03-18 14:50:19 -04:00
|
|
|
}
|