From owner-freebsd-hackers@freebsd.org Thu Jan 21 22:45:16 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 9B927A8C9AB for ; Thu, 21 Jan 2016 22:45:16 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (relay04.stack.nl [IPv6:2001:610:1108:5010::107]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client CN "mailhost.stack.nl", Issuer "CA Cert Signing Authority" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 67C1F1A02 for ; Thu, 21 Jan 2016 22:45:16 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mx1.stack.nl (Postfix) with ESMTP id 831DFB806A; Thu, 21 Jan 2016 23:45:11 +0100 (CET) Received: by snail.stack.nl (Postfix, from userid 1677) id 705BB28494; Thu, 21 Jan 2016 23:45:11 +0100 (CET) Date: Thu, 21 Jan 2016 23:45:11 +0100 From: Jilles Tjoelker To: "Batutis, Ed" Cc: Mateusz Guzik , "freebsd-hackers@freebsd.org" , Diane Bruce , Joerg Sonnenberger Subject: Re: get number of open files in a process? Message-ID: <20160121224511.GA74045@stack.nl> References: <20160121153636.GA10961@britannica.bec.de> <20160121161637.GA83843@night.db.net> <20160121162527.GA11600@britannica.bec.de> <20160121191308.GA21869@dft-labs.eu> <31126442b7d347c5976a57aabc2e5792@hioexcmbx08-prd.hq.netapp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <31126442b7d347c5976a57aabc2e5792@hioexcmbx08-prd.hq.netapp.com> User-Agent: Mutt/1.5.21 (2010-09-15) 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 22:45:16 -0000 On Thu, Jan 21, 2016 at 07:44:01PM +0000, Batutis, Ed wrote: > > However, the real question is what do you need this for. > I would like to know when I am getting close to hitting the file > handle limit. This is useful for two reasons: 1) if I run out of > available file handles this will most likely cause my process to > crash. If I start logging when the count begins to get dangerously > high, then I might after the fact be able to determine what was going > on to cause that. 2) Some handles are used by a user interface. It > would be nice if the server could reject connections when the open > handle count hit a critical threshold so the user interface doesn't > become part of the problem - obscuring the actual underlying cause. You can check the integer file descriptor that was just created, since if the descriptor is N, at least N other descriptors must be active at the same time. For example, if a new client's file descriptor is higher than the limit minus some safety margin, reject the connection. -- Jilles Tjoelker