US Trends

how to get the open files for g

To list open files for a running process on Linux, the usual ways are lsof or the /proc filesystem. For the current shell, lsof -p $$ shows the files it has open, and ls -l /proc/$$/fd shows the file descriptors directly.

Quick commands

  • See open files for the current shell:
    lsof -p $$
  • See only file descriptors:
    ls -l /proc/$$/fd
  • See files for a specific process:
    lsof -p <PID>

If you meant another system

On FreeBSD, procstat -f <PID> is the common equivalent, and /dev/fd can also be used. If you meant Google Drive “open files,” then you open files from Drive by going to Drive, logging in, and double-clicking the file.

Tiny example

If you want the open files for process 1234, run:

bash

lsof -p 1234

And if you want just the descriptor links:

bash

ls -l /proc/1234/fd