How to check number of file handles used by process ??? - Linux

This is a discussion on How to check number of file handles used by process ??? - Linux ; Hi all! Is there any way to ask system about number of file handles used by specific process. Some syscall doing something like this: lsof | grep | wc -l but more efficiently ? regards Jarek...

+ Reply to Thread
Results 1 to 5 of 5

Thread: How to check number of file handles used by process ???

  1. How to check number of file handles used by process ???

    Hi all!

    Is there any way to ask system about number of file handles used by
    specific process. Some syscall doing something like this:

    lsof | grep | wc -l

    but more efficiently ?

    regards
    Jarek

  2. Re: How to check number of file handles used by process ???

    Jarek writes:

    > Is there any way to ask system about number of file handles
    > used by specific process.


    From within the process, or from "outside" ?

    > Some syscall doing something like this:
    > lsof | grep | wc -l


    I don't believe any such syscall exist.

    > but more efficiently ?


    If /proc is mounted and you are not looking for a portable solution,
    this will probably be more efficient:

    ls /proc//fd | wc -l

    Cheers,
    --
    In order to understand recursion you must first understand recursion.
    Remove /-nsp/ for email.

  3. Re: How to check number of file handles used by process ???

    > Is there any way to ask system about number of file handles used by
    > specific process. Some syscall doing something like this:
    >
    > lsof | grep | wc -l
    >
    > but more efficiently ?


    For a shell solution, note that Paul has already mentioned
    "wc -l /proc/NNNNN/fd" which is more efficient than lsof.

    From inside the process itself: iterate fstat(j, &buf) for j from 0 to
    the maximum file descriptor for your system, and check for non-error.

    From a different process: use the POSIX readdir() function [or the
    bare Linux system call getdents()] on /proc/NNNNN/fd, where NNNNN is
    the process number. /proc must be mounted, and you must have permissions.

    --

  4. Re: How to check number of file handles used by process ???

    John Reiser wrote:
    >> Is there any way to ask system about number of file handles used by
    >> specific process. Some syscall doing something like this:
    >>
    >> lsof | grep | wc -l
    >>
    >> but more efficiently ?

    >
    > For a shell solution, note that Paul has already mentioned
    > "wc -l /proc/NNNNN/fd" which is more efficient than lsof.
    >
    > From inside the process itself: iterate fstat(j, &buf) for j from 0 to
    > the maximum file descriptor for your system, and check for non-error.
    >
    > From a different process: use the POSIX readdir() function [or the
    > bare Linux system call getdents()] on /proc/NNNNN/fd, where NNNNN is
    > the process number. /proc must be mounted, and you must have permissions.


    Thanks!

    Jarek.

  5. Re: How to check number of file handles used by process ???

    On 2007-01-22, Jarek wrote:
    > Hi all!
    >
    > Is there any way to ask system about number of file handles used by
    > specific process. Some syscall doing something like this:
    >
    > lsof | grep | wc -l
    >
    > but more efficiently ?



    look in /proc/%d/fd/

    (where %d is the PID )

    Bye.
    Jasen

+ Reply to Thread