1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-04-26 13:48:59 +08:00

process[linux]: calculate the CreateTime and then convert to microseconds

This commit is contained in:
andy 2015-09-28 16:18:53 +01:00
parent 0fd612ec7b
commit cf5660bfd3
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) {