process.go
1package process
2
3import (
4 "os"
5 "syscall"
6)
7
8// IsRunning tell is a process is running
9func IsRunning(pid int) bool {
10 // never return no error in a unix system
11 process, err := os.FindProcess(pid)
12
13 if err != nil {
14 return false
15 }
16
17 // Signal 0 doesn't do anything but allow testing the process
18 err = process.Signal(syscall.Signal(0))
19
20 // Todo: distinguish "you don't have access" and "process doesn't exist"
21
22 return err == nil
23}