Source file
src/os/executable_procfs.go
Documentation: os
1
2
3
4
5
6
7
8 package os
9
10 import (
11 "errors"
12 "runtime"
13 )
14
15 func executable() (string, error) {
16 var procfn string
17 switch runtime.GOOS {
18 default:
19 return "", errors.New("Executable not implemented for " + runtime.GOOS)
20 case "linux", "android":
21 procfn = "/proc/self/exe"
22 case "netbsd":
23 procfn = "/proc/curproc/exe"
24 }
25 path, err := Readlink(procfn)
26
27
28
29 return stringsTrimSuffix(path, " (deleted)"), err
30 }
31
32
33 func stringsTrimSuffix(s, suffix string) string {
34 if len(s) >= len(suffix) && s[len(s)-len(suffix):] == suffix {
35 return s[:len(s)-len(suffix)]
36 }
37 return s
38 }
39
View as plain text