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

[host][linux] Change to use unix.SysInfo_t to get Uptime in Linux

This commit is contained in:
shirou 2020-09-19 11:12:05 +09:00
parent c5b7357407
commit 6c9f3bdcae

View File

@ -70,11 +70,11 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) {
}
func UptimeWithContext(ctx context.Context) (uint64, error) {
boot, err := BootTime()
if err != nil {
sysinfo := &unix.Sysinfo_t{}
if err := unix.Sysinfo(sysinfo); err != nil {
return 0, err
}
return timeSince(boot), nil
return uint64(sysinfo.Uptime), nil
}
func UsersWithContext(ctx context.Context) ([]UserStat, error) {