6c9628cdb1
* Rename 'vendor/src' -> 'vendor' * Ignore vendor/ instead of vendor/src/ for lint * Rename 'cmd/client' -> 'cmd/ocic' to make it 'go install'able * Rename 'cmd/server' -> 'cmd/ocid' to make it 'go install'able * Update Makefile to build and install from GOPATH * Update tests to locate ocid/ocic in GOPATH/bin * Search for binaries in GOPATH/bin instead of PATH * Install tools using `go get -u`, so they are updated on each run Signed-off-by: Jonathan Yu <jawnsy@redhat.com>
27 lines
786 B
Go
27 lines
786 B
Go
package system
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"path/filepath"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// look in /proc to find the process start time so that we can verify
|
|
// that this pid has started after ourself
|
|
func GetProcessStartTime(pid int) (string, error) {
|
|
data, err := ioutil.ReadFile(filepath.Join("/proc", strconv.Itoa(pid), "stat"))
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
parts := strings.Split(string(data), " ")
|
|
// the starttime is located at pos 22
|
|
// from the man page
|
|
//
|
|
// starttime %llu (was %lu before Linux 2.6)
|
|
// (22) The time the process started after system boot. In kernels before Linux 2.6, this
|
|
// value was expressed in jiffies. Since Linux 2.6, the value is expressed in clock ticks
|
|
// (divide by sysconf(_SC_CLK_TCK)).
|
|
return parts[22-1], nil // starts at 1
|
|
}
|