process_unix.go 417 B

123456789101112131415161718192021222324
  1. // +build linux freebsd darwin
  2. package system
  3. import (
  4. "syscall"
  5. "golang.org/x/sys/unix"
  6. )
  7. // IsProcessAlive returns true if process with a given pid is running.
  8. func IsProcessAlive(pid int) bool {
  9. err := unix.Kill(pid, syscall.Signal(0))
  10. if err == nil || err == unix.EPERM {
  11. return true
  12. }
  13. return false
  14. }
  15. // KillProcess force-stops a process.
  16. func KillProcess(pid int) {
  17. unix.Kill(pid, unix.SIGKILL)
  18. }