aboutsummaryrefslogtreecommitdiffstats
path: root/util/process.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-08-21 18:46:53 +0200
committerMichael Muré <batolettre@gmail.com>2018-08-21 19:13:08 +0200
commit6d7dc465d881d0d04b01dfb6e09870346216d2d0 (patch)
treefbbce01c6b7634556303a3d917d1036767280d17 /util/process.go
parent942178288d657202b3f7afd386b319a245afbb7e (diff)
downloadgit-bug-6d7dc465d881d0d04b01dfb6e09870346216d2d0.tar.gz
cache: lock the repo with a pid file; automatic cleaning
Diffstat (limited to 'util/process.go')
-rw-r--r--util/process.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/util/process.go b/util/process.go
new file mode 100644
index 00000000..ddd3f704
--- /dev/null
+++ b/util/process.go
@@ -0,0 +1,23 @@
+package util
+
+import (
+ "os"
+ "syscall"
+)
+
+// ProcessIsRunning tell is a process is running
+func ProcessIsRunning(pid int) bool {
+ // never return no error in a unix system
+ process, err := os.FindProcess(pid)
+
+ if err != nil {
+ return false
+ }
+
+ // Signal 0 doesn't do anything but allow testing the process
+ err = process.Signal(syscall.Signal(0))
+
+ // Todo: distinguish "you don't have access" and "process doesn't exist"
+
+ return err == nil
+}