Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not cache boot time for linux. Fix #837 #857

Merged
merged 1 commit into from
May 17, 2020
Merged

Conversation

Gui13
Copy link

@Gui13 Gui13 commented Apr 15, 2020

This should fix the issue #837: we now query the value of /proc/stat or /proc/uptime at each invocation.

Not doing so will not return the correct boot time when NTP adjusts the time of the system in linux.

@Lomanic
Copy link
Collaborator

Lomanic commented Apr 18, 2020

Could you test this with and without your patch applied please?

  1. stop the NTP service
  2. Reboot so that time is wrong on the Raspberry Pi
  3. Launch this program below, before ntpd kicks in
  4. Launch ntpd, time jumps
  5. Observe what's reported by this test program (is it still reported as running after time jumps?)
package main

import (
        "fmt"
        "os"
        "time"

        "github.com/shirou/gopsutil/process"
)

func main() {
        p, _ := process.NewProcess(int32(os.Getpid()))

        c := time.Tick(5 * time.Second)
        for range c {
                fmt.Printf("%s ", time.Now())
                fmt.Println(p.IsRunning())
        }
}

@Lomanic
Copy link
Collaborator

Lomanic commented May 12, 2020

I was able to test my program above on my Rapsberry Pi and IsRunning() is returning false for the current process after time jumps, with or without this patch. I didn't test host.Uptime() though, but it's probably good. Will test it soon and merge if OK. Thanks for your patience.

@Lomanic Lomanic merged commit c89193f into shirou:master May 17, 2020
@Lomanic
Copy link
Collaborator

Lomanic commented May 17, 2020

We should use unix.Sysinfo in the future to get uptime on Linux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants