-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Process.StartTime on macOS returns different values #30241
Comments
In the attached code, the PID I was using was for Microsoft Outlook on my laptop. It was launched one time, but the StartTime drifted and no 2 consecutive calls got the same value. |
@danmosemsft I'm reading this and I am concerned that there is a similar issue in Linux not being addressed by just fixing Process.OSX.cs |
We likely won't have time to look at this for a a little while, so if either of you feel motivated to work on PR(s) that would be welcome. |
I've been away from OS X programming for some time (and my MBP is too old to run .NET Core), but would Untested: /// <summary>Gets the time the associated process was started.</summary>
private int StartTimeCore
{
get
{
EnsureState(State.HaveNonExitedId);
Interop.libproc.proc_taskallinfo? info = Interop.libproc.GetProcessInfoById(Id);
if (info == null)
throw new Win32Exception(SR.ProcessInformationUnavailable);
// ignores microseconds
return DateTime.UnixEpoch + TimeSpan.FromSeconds(info.pbsd.pbi_start_tvsec);
}
} |
@mdolan92869 I've put up a branch which attempts a fix if you can test (my MBP cannot run .NET Core). @jpfreyen it looks like the Linux code falls back on UtcNow if it can't read the boot time from |
@watfordgnf I would agree, pbi_start_tvsec/pbi_start_tvusec would be a good place to start for macOS. And @watfordgnf do you mean /proc/{pid}/stat instead of /proc/stat? Or wait, if /proc/stat somehow can't be read then .NETCore doesn't bother with individual process stats at /proc/{pid}/stat, right? |
It pulls |
I've opened draft PR dotnet/corefx#39572 to iterate on a possible implementation. |
Thanks for the fix @watfordgnf; I can't help test, my work environment is totally not setup to build .NETCore code changes and try them. |
* Use pbi_start for StartTime on OS X fixes #39434 * Add test to ensure StartTime remains stable * Reduce delay in test based on feedback - Use the correct Assert.Equal too. * Ensure StartTime is in Local Time * Remove unnecessary test and reenable other test for OS X * Remove unused OS X interop methods - SystemNative_GetAbsoluteTime - SystemNative_GetTimebaseInfo * Remove cmake entries for unused HAVE_MACH_TIMEBASE_INFO * Address review comment regarding constants
When getting the StartTime for a process, each time it's called for a new instance of the same process, it has a different value. I believe that the issue is in StartTimeCore where the native "now" time is retrieved, a bunch of arithmetic is performed, then the C# "now" time is retrieved. Since operations were between the two "now" calls, the "now" values will obviously be different, but they're used as if they're the same. I've attached a sample program that will show the deltas between StartTime accesses.
System: macOS 10.14.5 Mojave
ProcessStartTime.zip
The text was updated successfully, but these errors were encountered: