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
{{ message }}
Repository navigation
System.ComponentModel.Win32Exception when trying get Process.StartTime in the exited process on Linux #18540
I think the real bug here is that this works on Windows.
From the doc:
Process.StartTime
Type: System.DateTime
An object that indicates when the process started. An exception is thrown if the process is not running.
[...]
InvalidOperationException The process has exited.
Which is the behavior displayed on Linux (though not the right exception).
In Windows code, we call GetProcessHandle which can throw InvalidOperationException on an exited process, but we call it with throwOnExited == false.
Having the same behavior on all platforms sounds important, but I'm not sure changing the Windows behavior is the best move. Another option is to return StartTime even when the process has exited on Linux and to update the doc. @stephentoub, Thoughts?
Linux also throws Win32Exceptions on *ProcessorTime (after exit) and those don't mention exited processes in the doc, so I'm not sure how we'd want to handle those.
If we decide to go with the later option, for StartTime on Linux, we can cache it when we first get a chance to query it (as it's not going to change), but for *ProcessorTime, those would change up until we exit (and then /proc/PID will be gone), so I don't know how to address those.
@mbinette91@SerhiiS-in6k On windows, if the pinvoke failed to get starttime, we throw Win32Exception, here, and invalidoperationexception is thrown when the handle is invalid indicating process exit. On Linux, there is no good way to determine why the proc/stat file parsing failed, could be process exited or hasn't started or any other OS error, hence we throw Win32Exception, in accordance to Windows behavior.
Activity
mbinette91 commentedon Oct 7, 2016
I think the real bug here is that this works on Windows.
From the doc:
Which is the behavior displayed on Linux (though not the right exception).
In Windows code, we call GetProcessHandle which can throw InvalidOperationException on an exited process, but we call it with throwOnExited == false.
Having the same behavior on all platforms sounds important, but I'm not sure changing the Windows behavior is the best move. Another option is to return StartTime even when the process has exited on Linux and to update the doc. @stephentoub, Thoughts?
Linux also throws Win32Exceptions on *ProcessorTime (after exit) and those don't mention exited processes in the doc, so I'm not sure how we'd want to handle those.
If we decide to go with the later option, for StartTime on Linux, we can cache it when we first get a chance to query it (as it's not going to change), but for *ProcessorTime, those would change up until we exit (and then /proc/PID will be gone), so I don't know how to address those.
Priya91 commentedon Dec 7, 2016
@mbinette91 @SerhiiS-in6k On windows, if the pinvoke failed to get starttime, we throw Win32Exception, here, and invalidoperationexception is thrown when the handle is invalid indicating process exit. On Linux, there is no good way to determine why the proc/stat file parsing failed, could be process exited or hasn't started or any other OS error, hence we throw Win32Exception, in accordance to Windows behavior.
Closing issue, please reopen if required.