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

CreateTime() on linux returning an incorrect timestamp
pull/89/head
shirou 10 years ago
commit 82a76c01e3

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

@ -270,9 +270,17 @@ func Test_Process_CreateTime(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("error %v", err) t.Errorf("error %v", err)
} }
if c < 1420000000 { if c < 1420000000 {
t.Errorf("process created time is wrong.") 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) { func Test_Parent(t *testing.T) {

Loading…
Cancel
Save