You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From what I can tell, the current implementation is simply relying on .NET which calls the native clock_gettime() function. However, it may request CLOCK_MONOTONIC which gives the time since the system booted, but does NOT include any time when the system was suspended. It seems that it should be CLOCK_BOOTTIME which includes any suspended time. Looking through the .NET source, they only use CLOCK_BOOTTIME to calculate the start time of processes and is not public. So it seems the best option is to P/Invoke the API on non-Windows.
I think it might depend on your distro as the reference code does have different API calls depending on what is available on the system. On my Ubuntu 22.04 install, uptime -p and get-uptime match.
but does NOT include any time when the system was suspended.
Yes, after reboot values was identical, when I closed the lid of laptop for three minutes I got the difference in values.
Perhaps it would be correct to take timespan from the last boot time?
$ who -b
system boot 2022-11-05 11:39
$ (last -x reboot)[0]
reboot system boot 6.0.7-arch1-1 Sat Nov 5 11:39 still running
Looking through the .NET source, they only use CLOCK_BOOTTIME to calculate the start time of processes and is not public. So it seems the best option is to P/Invoke the API on non-Windows.
This doesn't work on all platforms.
Best option is to request new API in .Net System.Environment.Uptime.
Until that, since it is not critical, we could add a workaround for Linux systems and use /proc/uptime.
We use Stopwatch.GetTimestamp() and if it takes into account suspend time on Windows but not on Unix this looks like a bug. It makes sense to open new issue in .Net Runtime repository.
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 15, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 22, 2023
Activity
SteveL-MSFT commentedon Nov 5, 2022
From what I can tell, the current implementation is simply relying on .NET which calls the native
clock_gettime()function. However, it may requestCLOCK_MONOTONICwhich gives the time since the system booted, but does NOT include any time when the system was suspended. It seems that it should beCLOCK_BOOTTIMEwhich includes any suspended time. Looking through the .NET source, they only useCLOCK_BOOTTIMEto calculate the start time of processes and is not public. So it seems the best option is to P/Invoke the API on non-Windows.SteveL-MSFT commentedon Nov 5, 2022
I think it might depend on your distro as the reference code does have different API calls depending on what is available on the system. On my Ubuntu 22.04 install,
uptime -pandget-uptimematch.237dmitry commentedon Nov 5, 2022
Yes, after reboot values was identical, when I closed the lid of laptop for three minutes I got the difference in values.
Perhaps it would be correct to take timespan from the last boot time?
iSazonov commentedon Nov 5, 2022
This doesn't work on all platforms.
Best option is to request new API in .Net
System.Environment.Uptime.Until that, since it is not critical, we could add a workaround for Linux systems and use
/proc/uptime.237dmitry commentedon Nov 5, 2022
This works.
iSazonov commentedon Nov 5, 2022
We use
Stopwatch.GetTimestamp()and if it takes into account suspend time on Windows but not on Unix this looks like a bug. It makes sense to open new issue in .Net Runtime repository.SteveL-MSFT commentedon Nov 7, 2022
Ilya (@iSazonov) I tend to agree that this seems like a bug that should be fixed in .NET
microsoft-github-policy-service commentedon Nov 15, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 15, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 15, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 22, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.
xtqqczze commentedon Oct 8, 2025
Ryan Yates (@kilasuit) Please reopen.