Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Finding the Parent Process

Finding the Parent Process

Scheduled Pinned Locked Moved C / C++ / MFC
questioncomdata-structuresjsonhelp
10 Posts 4 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Richard Andrew x64R Offline
    Richard Andrew x64R Offline
    Richard Andrew x64
    wrote on last edited by
    #1

    I'm using NtQueryInformationProcess[^] to find the parent process of a specified process. I'm passing a PROCESS_BASIC_INFORMATION structure and using the InheritedFromUniqueProcessId member to get the parent. I then call this function recursively with each parent process to find the parent of the parent, and so on. The problem is that sometimes it starts returning process IDs that it has already returned in earlier calls, leading to infinite recursion. For instance, in successive calls it will return process IDs 3, then 2, then 1. Then when called for process ID 1 it will return 3 again! How can this be? I can easily work around this by checking to see if the returned parent process ID was already returned earlier in the call stack, and if it was, breaking out of the loop. But my question is, why?

    The difficult we do right away... ...the impossible takes slightly longer.

    L D J 3 Replies Last reply
    0
    • Richard Andrew x64R Richard Andrew x64

      I'm using NtQueryInformationProcess[^] to find the parent process of a specified process. I'm passing a PROCESS_BASIC_INFORMATION structure and using the InheritedFromUniqueProcessId member to get the parent. I then call this function recursively with each parent process to find the parent of the parent, and so on. The problem is that sometimes it starts returning process IDs that it has already returned in earlier calls, leading to infinite recursion. For instance, in successive calls it will return process IDs 3, then 2, then 1. Then when called for process ID 1 it will return 3 again! How can this be? I can easily work around this by checking to see if the returned parent process ID was already returned earlier in the call stack, and if it was, breaking out of the loop. But my question is, why?

      The difficult we do right away... ...the impossible takes slightly longer.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Dynamic versus static structures? Different types of parents / qualifying information?

      "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

      Richard Andrew x64R 1 Reply Last reply
      0
      • L Lost User

        Dynamic versus static structures? Different types of parents / qualifying information?

        "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

        Richard Andrew x64R Offline
        Richard Andrew x64R Offline
        Richard Andrew x64
        wrote on last edited by
        #3

        Can you elaborate? I didn't know there were different types of parents. And I don't know what you mean by dynamic versus static structures.

        The difficult we do right away... ...the impossible takes slightly longer.

        L 1 Reply Last reply
        0
        • Richard Andrew x64R Richard Andrew x64

          I'm using NtQueryInformationProcess[^] to find the parent process of a specified process. I'm passing a PROCESS_BASIC_INFORMATION structure and using the InheritedFromUniqueProcessId member to get the parent. I then call this function recursively with each parent process to find the parent of the parent, and so on. The problem is that sometimes it starts returning process IDs that it has already returned in earlier calls, leading to infinite recursion. For instance, in successive calls it will return process IDs 3, then 2, then 1. Then when called for process ID 1 it will return 3 again! How can this be? I can easily work around this by checking to see if the returned parent process ID was already returned earlier in the call stack, and if it was, breaking out of the loop. But my question is, why?

          The difficult we do right away... ...the impossible takes slightly longer.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Some sort of circular dependency? You see a similar behavior if you've ever used Dependency Walker.

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

          Richard Andrew x64R J 2 Replies Last reply
          0
          • D David Crow

            Some sort of circular dependency? You see a similar behavior if you've ever used Dependency Walker.

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

            Richard Andrew x64R Offline
            Richard Andrew x64R Offline
            Richard Andrew x64
            wrote on last edited by
            #5

            Yes I see what you're saying. The only kind of dependency that I am familiar with is the static kind used by DLLs. What kind of dependency are you discussing?

            The difficult we do right away... ...the impossible takes slightly longer.

            1 Reply Last reply
            0
            • Richard Andrew x64R Richard Andrew x64

              Can you elaborate? I didn't know there were different types of parents. And I don't know what you mean by dynamic versus static structures.

              The difficult we do right away... ...the impossible takes slightly longer.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              If I'm climbing a tree and the branch I'm climbing gets moved, what am I climbing? I child can have multiple parents. You need to know which parent you're dealing with. If they inherit the same base, they "look" the same but aren't.

              "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

              Richard Andrew x64R 1 Reply Last reply
              0
              • L Lost User

                If I'm climbing a tree and the branch I'm climbing gets moved, what am I climbing? I child can have multiple parents. You need to know which parent you're dealing with. If they inherit the same base, they "look" the same but aren't.

                "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                Richard Andrew x64R Offline
                Richard Andrew x64R Offline
                Richard Andrew x64
                wrote on last edited by
                #7

                I don't see how a process can have more than one parent process. This is something I hadn't considered. If Process A calls CreateProcess and launches Process B. Then A is the parent. I don't see how any other process can be a parent of B.

                The difficult we do right away... ...the impossible takes slightly longer.

                1 Reply Last reply
                0
                • D David Crow

                  Some sort of circular dependency? You see a similar behavior if you've ever used Dependency Walker.

                  "One man's wage rise is another man's price increase." - Harold Wilson

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                  J Offline
                  J Offline
                  jschell
                  wrote on last edited by
                  #8

                  I have seen that also. Annoying when it showed up an I always ignored it without considering the reason why.

                  1 Reply Last reply
                  0
                  • Richard Andrew x64R Richard Andrew x64

                    I'm using NtQueryInformationProcess[^] to find the parent process of a specified process. I'm passing a PROCESS_BASIC_INFORMATION structure and using the InheritedFromUniqueProcessId member to get the parent. I then call this function recursively with each parent process to find the parent of the parent, and so on. The problem is that sometimes it starts returning process IDs that it has already returned in earlier calls, leading to infinite recursion. For instance, in successive calls it will return process IDs 3, then 2, then 1. Then when called for process ID 1 it will return 3 again! How can this be? I can easily work around this by checking to see if the returned parent process ID was already returned earlier in the call stack, and if it was, breaking out of the loop. But my question is, why?

                    The difficult we do right away... ...the impossible takes slightly longer.

                    J Offline
                    J Offline
                    jschell
                    wrote on last edited by
                    #9

                    Seems like an interesting question. Googling I found nothing that answers that. From the other post I did find a comment in 'Dependency Walker' but that only stated that it occurred but not why. Maybe you could determine the cause by looking at the detailed process information and comparing them?

                    Richard Andrew x64R 1 Reply Last reply
                    0
                    • J jschell

                      Seems like an interesting question. Googling I found nothing that answers that. From the other post I did find a comment in 'Dependency Walker' but that only stated that it occurred but not why. Maybe you could determine the cause by looking at the detailed process information and comparing them?

                      Richard Andrew x64R Offline
                      Richard Andrew x64R Offline
                      Richard Andrew x64
                      wrote on last edited by
                      #10

                      Thanks for your responses. I wish I had a line to Mark Russinovich. I'm sure he would know.

                      The difficult we do right away... ...the impossible takes slightly longer.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups