From owner-freebsd-hackers@FreeBSD.ORG Mon Apr 9 15:35:25 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 3DE3D16A400 for ; Mon, 9 Apr 2007 15:35:25 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.freebsd.org (Postfix) with ESMTP id ECCC813C4D5 for ; Mon, 9 Apr 2007 15:35:14 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (dan@localhost [127.0.0.1]) by dan.emsphone.com (8.14.0/8.13.8) with ESMTP id l39FZ8fc074316 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 9 Apr 2007 10:35:08 -0500 (CDT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.14.0/8.14.0/Submit) id l39FZ82L074315; Mon, 9 Apr 2007 10:35:08 -0500 (CDT) (envelope-from dan) Date: Mon, 9 Apr 2007 10:35:08 -0500 From: Dan Nelson To: Garrett Cooper Message-ID: <20070409152956.GB93087@dan.emsphone.com> References: <46192EFC.6030906@u.washington.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <46192EFC.6030906@u.washington.edu> X-OS: FreeBSD 6.2-STABLE User-Agent: Mutt/1.5.14 (2007-02-12) Cc: freebsd-hackers@freebsd.org Subject: Re: Discovering list of open files from "kernel level" without using utils like lsof X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Apr 2007 15:35:25 -0000 In the last episode (Apr 08), Garrett Cooper said: > I'm trying to see whether it's possible to grab the list of > files open from a kernel level on FreeBSD, using a userland library > interface as opposed to lsof. > I'm trying to see if there's a simple tool that I could code in > C/C++ if necessary to spin down disks automatically to save power and > disk life. Plus, I think that lsof actually would probe the devices > and 'wake them up' instead of keeping them as-is. However, I could be > wrong so if I am please let me know. Take a look at how /usr/bin/fstat does it. There is apparently a "kern.file" sysctl that holds the open file table, but fstat digs through kernel memory. -- Dan Nelson dnelson@allantgroup.com