[Mono-list] Getting parent process

Jonathan Pryor jonpryor at vt.edu
Wed Jan 25 19:02:08 EST 2006


On Wed, 2006-01-25 at 11:03 -0300, Mariano Benedettini wrote:
> How can I build a process tree ?
> Say, starting from the current process id, get the parent of it and 
> successively.
> With Mono.Unix.Process.GetCurrentProcessId() and 
> Mono.Unix.UnixEnvironment.GetParentProcessId() I can get the current 
> process and its parent, but cant go further :-(

The short answer is that you don't, at least not while sticking strictly
to POSIX.  I don't know why, but that information is not exposed.

This doesn't mean it's not possible, it just means it's not in POSIX
(and thus not portable).  pstree(1) reads the Linux /proc file system to
build the process tree; see:

http://cvs.sourceforge.net/viewcvs.py/psmisc/psmisc/src/pstree.c?rev=1.32&view=markup

 - Jon




More information about the Mono-list mailing list