Skip to content

System.ComponentModel.Win32Exception when trying get Process.StartTime in the exited process on Linux #18540

Closed

Description

@SerhiiS-in6k

Activity

  1. mbinette91 commented on Oct 7, 2016

    @mbinette91

    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.

  2. Priya91 commented on Dec 7, 2016

    @Priya91
    Contributor

    @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.

  3. transferred this issue fromdotnet/corefxon Jan 31, 2020
  4. added this to the 2.0.0 milestone on Jan 31, 2020
  5. ghost locked as resolved and limited conversation to collaborators on Dec 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions