Skip to content

Extend System.Diagnostics.Process with a ParentProcess property #2763

Closed

Description

It is unreasonably obscure to get the parent of a process via PowerShell today.
Get-Command -Noun Process will not give you anything, and you have to know that
there is a ParentProcessId on Get-CimInstance win32_process. Even when you know that, you have to understand recycling of process ids and that you have to check the start time of the processes to actually know if it is your parent.

On top of that Get-CimInstance win32_process is dog slow due to some repetitive loading of mui dlls for some time zone related localization.

I suggest an extended property Diagnostics.Process ParentProcess {get;} that does the heavy lifting for the user in a fast and correct manner.

I don't know if it is valuable to also expose the ParentPid. (You were started by a process that had this id at the time when our your process started). Thoughts?

Activity

  1. added
    WG-Cmdlets
    Issue-Enhancement
    Up-for-Grabs
    on Nov 22, 2016
  2. powercode commented on Nov 22, 2016

    @powercode
    CollaboratorAuthor

    I can't find what src\System.Management.Automation\engine\Types_Ps1Xml.generated.cs is generated from.
    Any hints?

  3. powercode commented on Nov 22, 2016

    @powercode
    CollaboratorAuthor

    Or was it generated once upon a time, but isn't any longer?

  4. powercode commented on Nov 22, 2016

    @powercode
    CollaboratorAuthor

    Initial (working on WinFull) at https://github.com/powercode/PowerShell/tree/process-parentpid

    What's the deal here regarding platform differences?
    I'm not really well versed enough to say how to implement this on Linux/maxos.
    Pointers?

  5. iSazonov commented on Nov 24, 2016

    @iSazonov
    Collaborator

    I can't find what src\System.Management.Automation\engine\Types_Ps1Xml.generated.cs is generated from.
    Any hints?

    The file's history say that you can modify it.

  6. iSazonov commented on Nov 24, 2016

    @iSazonov
    Collaborator

    What's the deal here regarding platform differences?
    I'm not really well versed enough to say how to implement this on Linux/maxos.
    Pointers?

    Start from libpsl-native getcurrentprocessorid

    I think you can easy add and use getppid

  7. powercode commented on Dec 6, 2016

    @powercode
    CollaboratorAuthor

    getppid is just the parent of the current process.
    I think I have to read /proc/pid/stat to get the ppid of a specific pid.

  8. iSazonov commented on Dec 7, 2016

    @iSazonov
    Collaborator

    Yes, read /proc right direction.

  9. powercode commented on Dec 7, 2016

    @powercode
    CollaboratorAuthor

    I'm getting a test error when Import/Export-CliXml with process after adding the Parent property to Process.
    Is there any way to opt out a property from clixml serialization?

  10. lzybkr commented on Dec 7, 2016

    @lzybkr
    Contributor

    I don't know why the tests are failing in CI. I tried your changes it it works for me locally.

    You can try debugging in CI. On AppVeyor, you can follow these instructions:

    https://www.appveyor.com/docs/how-to/rdp-to-build-worker/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-EnhancementResolution-FixedUp-for-GrabsWG-Cmdlets

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions