L
linuxfedora
Hi All,
How to get the parent process ID of a process, thanks
Beside using performanceCounter
i found that we can use lpfCreateToolhelp32Snapshot, but i cannot
convert it to win32 version correctly, what is the problem?Thanks
[DllImport("Psapi.dll")]
private static extern IntPtr lpfCreateToolhelp32Snapshot(int
value, int value1);
[DllImport("Kernel32.dll")]
private static extern bool lpfProcess32First(IntPtr pointer,
out PROCESSENTRY32 value);
[DllImport("Kernel32.dll")]
private static extern bool lpfProcess32Next(IntPtr pointer,
out PROCESSENTRY32 value);
[StructLayout(LayoutKind.Sequential)]
public struct PROCESSENTRY32
{
public uint dwSize;
public uint cntUsage;
public uint th32ProcessID;
public IntPtr th32DefaultHeapID;
public uint th32ModuleID;
public uint cntThreads;
public uint th32ParentProcessID;
public int pcPriClassBase;
public uint dwFlags;
public string szExeFile;
}
private uint GetProcessParentID(int pid)
{
IntPtr hSnapShot = lpfCreateToolhelp32Snapshot(0x2, 0);
PROCESSENTRY32 procentry = new PROCESSENTRY32();
bool bContinue = lpfProcess32First(hSnapShot, out
procentry);
while (bContinue)
{
if (pid == procentry.th32ProcessID)
{
return procentry.th32ParentProcessID;
}
bContinue = lpfProcess32Next(hSnapShot, out
procentry);
}
return 0;
}
How to get the parent process ID of a process, thanks
Beside using performanceCounter
i found that we can use lpfCreateToolhelp32Snapshot, but i cannot
convert it to win32 version correctly, what is the problem?Thanks
[DllImport("Psapi.dll")]
private static extern IntPtr lpfCreateToolhelp32Snapshot(int
value, int value1);
[DllImport("Kernel32.dll")]
private static extern bool lpfProcess32First(IntPtr pointer,
out PROCESSENTRY32 value);
[DllImport("Kernel32.dll")]
private static extern bool lpfProcess32Next(IntPtr pointer,
out PROCESSENTRY32 value);
[StructLayout(LayoutKind.Sequential)]
public struct PROCESSENTRY32
{
public uint dwSize;
public uint cntUsage;
public uint th32ProcessID;
public IntPtr th32DefaultHeapID;
public uint th32ModuleID;
public uint cntThreads;
public uint th32ParentProcessID;
public int pcPriClassBase;
public uint dwFlags;
public string szExeFile;
}
private uint GetProcessParentID(int pid)
{
IntPtr hSnapShot = lpfCreateToolhelp32Snapshot(0x2, 0);
PROCESSENTRY32 procentry = new PROCESSENTRY32();
bool bContinue = lpfProcess32First(hSnapShot, out
procentry);
while (bContinue)
{
if (pid == procentry.th32ProcessID)
{
return procentry.th32ParentProcessID;
}
bContinue = lpfProcess32Next(hSnapShot, out
procentry);
}
return 0;
}