Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 22 Jan 2016 00:17:18 +0300
From:      Slawa Olhovchenkov <slw@zxy.spb.ru>
To:        "Batutis, Ed" <Ed.Batutis@netapp.com>
Cc:        "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org>
Subject:   Re: get number of open files in a process?
Message-ID:  <20160121211718.GI88527@zxy.spb.ru>
In-Reply-To: <ea9f2ab2d4f543c8ad34fdeb082f8c7a@hioexcmbx08-prd.hq.netapp.com>
References:  <ea9f2ab2d4f543c8ad34fdeb082f8c7a@hioexcmbx08-prd.hq.netapp.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Jan 21, 2016 at 01:34:18PM +0000, Batutis, Ed wrote:

> Hi,
> 
> I need to determine the number of open files in my process - all types of file handles total - sockets, files, everything.
> 
> Does this work reliably for that purpose?
> 
>    int num_open = 0; /* number of open files? */
>    kinfo_file *inf =  kinfo_getfile(getpid(), &num_open);
>    if ( inf ) {
>      free(inf);
>    }

# limits
Resource limits (current):
  cputime              infinity secs
  filesize             infinity kB
  datasize             33554432 kB
  stacksize              524288 kB
  coredumpsize         infinity kB
  memoryuse            infinity kB
  memorylocked         infinity kB
  maxprocesses             8485
  openfiles              116442
  sbsize               infinity bytes
  vmemoryuse           infinity kB
  pseudo-terminals     infinity
  swapuse              infinity kB

# df -ki /dev/fd/
Filesystem 1024-blocks Used Avail Capacity iused  ifree %iused  Mounted on
fdescfs              1    1     0   100%       4 116439    0%   /dev/fd
                                           ^^^^^ ^^^^^^



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20160121211718.GI88527>