Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sometimes I find myself in a cmd.exe environment that itself was started by another cmd.exe or by another console-based application. Now, working in such an environment, I'd like to know what happens if I type exit, that is, if the cmd.exe window will disappear, or if it goes back to the cmd.exe or application that invoked it. This, of course, because sometimes as I work in cmd.exe I forget about how I called it.

So, is there a way to find out the parent process (if this is the correct term) of a cmd.exe within another cmd.exe?

share|improve this question
1  
"parent process" is correct terminology, but i don't think "terminus" is... –  quack quixote Mar 17 '10 at 7:33
add comment

2 Answers

up vote 5 down vote accepted

You can use WMI to get this information. The Win32_Process class contains ParentProcessId

So (using PowerShell to execute WMI commands—other WMI tools are available):

gwmi Win32_Process -filter 'processid = 1234' | select ParentProcessId

will give the parent process id of process 1234.

share|improve this answer
    
I haven't tried this, but this sounds correct. Upvoted. –  Alexander Burke Mar 18 '10 at 4:59
    
(gwmi win32_process | ? processid -eq $pid).parentprocessid ($pid contains the current process id) –  Luke Sampson Aug 21 '13 at 23:29
    
@LukeSampson Why get all processes and then filter when WMI can do the filtering for you at source? (Ie. use the variable in the -filter parameter of Get-WmiObject (gwmi) rather than a separate Where-Object (?).) –  Richard Aug 22 '13 at 7:09
1  
@Richard because I'm lazy and don't want to learn about a special parameter? Anyway thanks for your answer, it helped me :) –  Luke Sampson Aug 22 '13 at 14:13
add comment

This isn't from within cmd.exe itself but Process Explorer has a tree view which shows parent processes.

alt text

share|improve this answer
2  
Yes, this is certainly correct, but I hoped there would be some command or something that I could type into cmd.exe. –  René Nyffenegger Mar 16 '10 at 9:41
1  
another SysInternals tool, pslist.exe, can also provide a tree view. unfortunately PPID (parent process ID) is not part of the general output, but if the cmd window was started by another application the tree view should show that relationship. technet.microsoft.com/en-us/sysinternals/bb896682.aspx –  quack quixote Mar 17 '10 at 7:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.