From owner-freebsd-hackers Sat Nov 21 04:40:19 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id EAA09772 for freebsd-hackers-outgoing; Sat, 21 Nov 1998 04:40:19 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from ceia.nordier.com (m2-28-dbn.dial-up.net [196.34.155.92]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id EAA09762 for ; Sat, 21 Nov 1998 04:40:14 -0800 (PST) (envelope-from rnordier@nordier.com) Received: (from rnordier@localhost) by ceia.nordier.com (8.8.7/8.6.12) id OAA00989; Sat, 21 Nov 1998 14:38:39 +0200 (SAT) From: Robert Nordier Message-Id: <199811211238.OAA00989@ceia.nordier.com> Subject: Re: Getting PID of parent pipe? In-Reply-To: <36555721.8E3D2CDF@tdx.co.uk> from Karl Pielorz at "Nov 20, 98 11:48:49 am" To: kpielorz@tdx.co.uk (Karl Pielorz) Date: Sat, 21 Nov 1998 14:38:37 +0200 (SAT) Cc: hackers@FreeBSD.ORG X-Mailer: ELM [version 2.4ME+ PL31 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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