Merge pull request #85 from andyjones/fix/created-time

CreateTime() on linux returning an incorrect timestamp
This commit is contained in:
shirou 2015-09-29 11:43:03 +09:00
commit 82a76c01e3
2 changed files with 10 additions and 2 deletions

View File

@ -596,8 +596,8 @@ func (p *Process) fillFromStat() (string, int32, *cpu.CPUTimesStat, int64, int32
if err != nil {
return "", 0, nil, 0, 0, err
}
ctime := (t / uint64(ClockTicks)) + uint64(bootTime)*1000
createTime := int64(ctime)
ctime := (t / uint64(ClockTicks)) + uint64(bootTime)
createTime := int64(ctime * 1000)
// p.Nice = mustParseInt32(fields[18])
// use syscall instead of parse Stat file

View File

@ -270,9 +270,17 @@ func Test_Process_CreateTime(t *testing.T) {
if err != nil {
t.Errorf("error %v", err)
}
if c < 1420000000 {
t.Errorf("process created time is wrong.")
}
gotElapsed := time.Since(time.Unix(int64(c/1000), 0))
maxElapsed := time.Duration(5 * time.Second)
if gotElapsed >= maxElapsed {
t.Errorf("this process has not been running for %v", gotElapsed)
}
}
func Test_Parent(t *testing.T) {