在Windows上查找父进程ID

时间:2011-09-20 14:20:26

标签: windows cmd

问题

给出进程ID&远程Windows主机上的命令行访问,如何找到其父级的PID?

解决方案

鉴于Marc B的答案,我们可以使用WMIC(命令样本here)并执行以下操作:

wmic process where (processid=PROCID_HERE) get parentprocessid

4 个答案:

答案 0 :(得分:52)

C:\> wmic process get processid,parentprocessid,executablepath|find "process id goes here"

答案 1 :(得分:5)

基于joslinm's solution in the question,这里有一个如何在批处理脚本中使用它的片段:

set PID=<this is the child process ID>
for /f "usebackq tokens=2 delims==" %%a in (`wmic process where ^(processid^=%PID%^) get parentprocessid /value`) do (
    set PARENT_PID=%%a
)

答案 2 :(得分:2)

在powershell中:

PS> wmic process  where '(processid=4632)' get 'processid,parentprocessid,executablepath'
ExecutablePath                                              ParentProcessId  ProcessId
C:\Program Files\Docker\Docker\Resources\com.docker.db.exe  4488             4632

答案 3 :(得分:1)

或者您可以在PowerShell中执行以下操作:

Get-CimInstance -className win32_process | where-object {$_.ProcessId -eq processId_goes_here } | select ParentProcessId, Name

您也可以按名称过滤带有$_.ProcessId属性的替换$_.Name