github.com/haraldrudell/parl@v0.4.176/mains/process-start-darwin.go (about) 1 //go:build darwin 2 3 /* 4 © 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/) 5 ISC License 6 */ 7 8 package mains 9 10 import ( 11 "os" 12 "time" 13 14 "github.com/haraldrudell/parl/perrors" 15 "golang.org/x/sys/unix" 16 ) 17 18 const ( 19 kernProcPid = "kern.proc.pid" 20 ) 21 22 // ProcessStartTime returns the time the executing process was started. 23 // Resolution is seconds, time zone is local 24 func ProcessStartTime() (createTime time.Time) { 25 26 var unixKinfoProc *unix.KinfoProc 27 var err error 28 if unixKinfoProc, err = unix.SysctlKinfoProc(kernProcPid, os.Getpid()); perrors.Is(&err, "unix.SysctlKinfoProc: %T %+[1]v", err) { 29 panic(err) 30 } 31 var unixTimeval unix.Timeval = unixKinfoProc.Proc.P_starttime 32 sec, nsec := unixTimeval.Unix() 33 createTime = time.Unix(sec, nsec) 34 return 35 }