peterson@Data-IO.COM (Joe Peterson) (10/10/90)
I have a simple question:
Is there a way to get the parent process id of any arbitrary
process id? I know of getpid() and getppid(), but those only
operate on the current process.
I want to build a pid trace for the current process such as
long pidtrace[REALLYBIG];
long pid;
int i;
i=0;
pid = getpid();
while(pid != BOOTPROCESS)
{
pidtrace[i] = pid;
++i;
pid = parentpid(pid);
}
where parentpid() is the magic function that I can't find.
Any ideas?
Joe Peterson
peterson@Data-IO.COM
rembo@unisoft.UUCP (Tony Rems) (10/13/90)
In article <2738@dataio.Data-IO.COM> peterson@Data-IO.COM (Joe Peterson) writes: >I have a simple question: > >Is there a way to get the parent process id of any arbitrary >process id? I know of getpid() and getppid(), but those only >operate on the current process. > >I want to build a pid trace for the current process such as > > long pidtrace[REALLYBIG]; > long pid; > int i; > > i=0; > pid = getpid(); > > while(pid != BOOTPROCESS) > { > pidtrace[i] = pid; > > ++i; > pid = parentpid(pid); > } > >where parentpid() is the magic function that I can't find. > >Any ideas? > >Joe Peterson >peterson@Data-IO.COM You could cheat and do a popen of "ps". Kernighan & Pike do it in their zap program in "The UNIX Programming Environment". -Tony