From owner-freebsd-hackers@freebsd.org Thu Jan 21 19:00:23 2016 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id F3475A8B77A for ; Thu, 21 Jan 2016 19:00:23 +0000 (UTC) (envelope-from Ed.Batutis@netapp.com) Received: from mx141.netapp.com (mx141.netapp.com [216.240.21.12]) (using TLSv1.2 with cipher RC4-SHA (128/128 bits)) (Client CN "mx141.netapp.com", Issuer "Symantec Class 3 Secure Server CA - G4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id CEF441270 for ; Thu, 21 Jan 2016 19:00:23 +0000 (UTC) (envelope-from Ed.Batutis@netapp.com) X-IronPort-AV: E=Sophos;i="5.22,326,1449561600"; d="scan'208";a="95646828" Received: from hioexcmbx07-prd.hq.netapp.com ([10.122.105.40]) by mx141-out.netapp.com with ESMTP; 21 Jan 2016 10:39:57 -0800 Received: from HIOEXCMBX08-PRD.hq.netapp.com (10.122.105.41) by hioexcmbx07-prd.hq.netapp.com (10.122.105.40) with Microsoft SMTP Server (TLS) id 15.0.1130.7; Thu, 21 Jan 2016 10:39:57 -0800 Received: from HIOEXCMBX08-PRD.hq.netapp.com ([::1]) by hioexcmbx08-prd.hq.netapp.com ([fe80::6575:4d3c:1907:ddb1%21]) with mapi id 15.00.1130.005; Thu, 21 Jan 2016 10:39:57 -0800 From: "Batutis, Ed" To: Joerg Sonnenberger , Diane Bruce CC: "freebsd-hackers@freebsd.org" Subject: RE: get number of open files in a process? Thread-Topic: get number of open files in a process? Thread-Index: AdFT1cxGnzmxie9rRAaN4NJqEtku+wAzsUMAAAFlx4AAAE76gAAMyqlg Date: Thu, 21 Jan 2016 18:39:44 +0000 Deferred-Delivery: Thu, 21 Jan 2016 18:39:00 +0000 Message-ID: References: <20160121153636.GA10961@britannica.bec.de> <20160121161637.GA83843@night.db.net> <20160121162527.GA11600@britannica.bec.de> In-Reply-To: <20160121162527.GA11600@britannica.bec.de> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.122.56.79] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 21 Jan 2016 19:08:26 +0000 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Jan 2016 19:00:24 -0000 > > > Use getdtablesize() to get the current largest known fd. If you > > > want, you can afterwards loop and use fcntl with F_GETFD to check if > > > the descriptor is still open. Since I need an open handle count I would have to do 2048 fcntl() calls in = my case. I'm afraid this doesn't look like a good idea, since it might happ= en a lot under certain circumstances. Looking at the source for kinfo_getfile, it seems like using this is not a = good idea because, according to a comment in bug 197695: https://www.mail-archive.com/freebsd-bugs@freebsd.org/msg21569.html the function uses a sysctl with KERN_PROC_FILEDESC which "might be slow". T= his function also does two memory allocations for data I don't need to look= at. So, I guess the answer is, for me anyway, that there is no sufficiently eff= icient way to get the number of open file handles from the system for my us= er-space application. But, if anyone has any more ideas, I'd be happy to hear them! Thanks, =3DEd