From owner-freebsd-questions@FreeBSD.ORG Tue May 11 14:15:23 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id A86BB1065672 for ; Tue, 11 May 2010 14:15:23 +0000 (UTC) (envelope-from dkmcnulty@gmail.com) Received: from mail-ew0-f224.google.com (mail-ew0-f224.google.com [209.85.219.224]) by mx1.freebsd.org (Postfix) with ESMTP id 336F48FC0C for ; Tue, 11 May 2010 14:15:22 +0000 (UTC) Received: by ewy24 with SMTP id 24so1266592ewy.13 for ; Tue, 11 May 2010 07:15:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=TXHTdWf9hvEwRF+gbu9EZmH1F8gbVixN4qkz1PPutjc=; b=K019dfBVU/Gyl1LOIPrMrtpStToreEPeW2gDTvBjbyreX4LjdHGJp3ffchX8Qmvxy2 ms/7JbmrD5I5ZuYCUIsNr/7bejxnWhQLLVgC+uJtSNiWBOThjc0/Z3LAjVOBxOtIe4RT NEOefHuMRiyIv40ipDhs7XSFHR3HinNSye7pE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=RSrXoj6IfHJrpSBcBZB2LQOVDDLjNqBEA15rfGrAIJMKYxfxkV+0VtP/2pYAVun7LU 08hT+g5zvNWfGHB98oXGYIFavdE/5og7AWVF+v4ltW3a8/IMgamkyOLsBIsIlGrfJRJd qFd8MaQFDLlTco8EUSjmLivovA4yuWbBE79cw= MIME-Version: 1.0 Received: by 10.239.192.72 with SMTP id d8mr552337hbi.66.1273587321830; Tue, 11 May 2010 07:15:21 -0700 (PDT) Received: by 10.239.153.198 with HTTP; Tue, 11 May 2010 07:15:17 -0700 (PDT) In-Reply-To: <20100503213936.GL14572@dan.emsphone.com> References: <20100503213936.GL14572@dan.emsphone.com> Date: Tue, 11 May 2010 09:15:17 -0500 Message-ID: From: Dan McNulty To: Dan Nelson Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: freebsd-questions@freebsd.org Subject: Re: Finding out when a child process forks or calls exec X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 May 2010 14:15:23 -0000 Hi all, I have been experimenting with ptrace to determine when a child process forks or calls exec. Particularly, I have explored tracing every system call entry and exit similar to what the truss utility does, and for my case, the performance impact of tracing every system call is too great. Is there a more efficient way than tracing every system call entry and exit to determine when a child process forks, calls exec, or creates a new LWP? Thanks a lot for your help! -Dan On Mon, May 3, 2010 at 4:39 PM, Dan Nelson wrote: > In the last episode (May 03), Dan McNulty said: >> I am trying to port a debugging tool that uses the ptrace interface from >> Linux to FreeBSD. =A0From what I can tell, the ptrace interface on FreeB= SD >> is pretty similar to the Linux interface; however, it doesn't appear tha= t >> the FreeBSD interface generate events when the child process forks, call= s >> exec, creates a new LWP, etc. =A0My question then is: >> >> Does FreeBSD provide any way to determine from a parent/tracing >> process if a child process has called fork, exec, exit, or created a >> new LWP? > > /usr/bin/truss watches for syscalls named "fork", "rfork", and "vfork", a= nd > when they return it forks another copy of itself to watch the child. =A0S= ee > /usr/src/usr.bin/truss/i386-fbsd.c and main.c (search for "in_fork"). > > You can tell when a new lwp is created because lwpid changes. =A0In setup= .c > the waitevent() function calls ptrace(PT_LWPINFO...) on every syscall > entry/exit so it's easy to track; it then calls the find_thread() functio= n > which allocates a new helper struct every time a new lwp appears. > > -- > =A0 =A0 =A0 =A0Dan Nelson > =A0 =A0 =A0 =A0dnelson@allantgroup.com > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.o= rg" >