Date: Sat, 21 Nov 1998 14:38:37 +0200 (SAT) From: Robert Nordier <rnordier@nordier.com> To: kpielorz@tdx.co.uk (Karl Pielorz) Cc: hackers@FreeBSD.ORG Subject: Re: Getting PID of parent pipe? Message-ID: <199811211238.OAA00989@ceia.nordier.com> In-Reply-To: <36555721.8E3D2CDF@tdx.co.uk> from Karl Pielorz at "Nov 20, 98 11:48:49 am"
next in thread | previous in thread | raw e-mail | index | archive | help
Karl Pielorz wrote: > Is there an 'easy' way of getting the PID of a parent process feeding a > command's stdin? > > e.g. > > cat something | foo | bar You can use getppid(2). But the answer will be the PID of the shell, in this instance. > > I need to get the PID of foo while running as bar... The problem is that foo is not the parent of bar in your example. The parent is the process that does the fork(2). If foo does exec bar itself (ie. somewhat like xargs): cat something | foo bar then getppid() will work. Given the PID of bar, the PID of foo will be more or less predictable, so you may be able to get by using (ps plus grep plus) heuristics. Otherwise, this should entail doing something similar to the fstat(1) logic. -- Robert Nordier To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199811211238.OAA00989>