Path: utzoo!attcan!uunet!unisoft!rembo From: rembo@unisoft.UUCP (Tony Rems) Newsgroups: comp.unix.questions Subject: Re: UNIX process id trace Keywords: unix pid Message-ID: <3166@unisoft.UUCP> Date: 13 Oct 90 01:09:39 GMT References: <2738@dataio.Data-IO.COM> Reply-To: rembo@unisoft.UUCP (Tony Rems) Lines: 35 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