I have the code below for getting a list of child processes on windows by interop'ing with ntdll. Is there an equivalent to 'NtQueryInformationProcess' on Linux, which get's me the process id of the parent of a specified process (like pbi.InheritedFromUniqueProcessId)? I need the code to run on Linux through Mono so hopefully I am hoping I need to change only the part where I get the parent process ID so the code stays mostly the same as on Windows.
public IList< Process > GetChildren( Process parent )
{
List< Process > children = new List< Process >();
Process[] processes = Process.GetProcesses();
foreach (Process p in processes)
{
ProcessBasicInformation pbi = new ProcessBasicInformation();
try
{
uint bytesWritten;
NtQueryInformationProcess(p.Handle,
0, ref pbi, (uint)Marshal.SizeOf(pbi),
out bytesWritten); // == 0 is OK
if (pbi.InheritedFromUniqueProcessId == parent.Id)
children.AddRange(GetChildren(p));
}
catch
{
}
}
return children;
}