Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find the file handles that my process has opened in Linux?

Tags:

c++

c

linux

file-io

When we perform a fork in Unix, open file handles are inherited, and if we don't need to use them we should close them. However, when we use libraries, file handles may be opened for which we do not have access to the handle. How do we check for these open file handles?

like image 480
sep Avatar asked Nov 06 '08 07:11

sep


People also ask

How do I find file handles in Linux?

In Linux you can check /proc/<pid>/fd directory - for every open fd there will be a file, named as handle.

How do I find the file descriptors of a process?

You can use /proc file system or the lsof command to find all the file descriptors used by a process.

Which command is used to identify list of open files by a process?

The open source lsof command is also useful for providing information about files opened by processes, and files opened under specific user accounts.


1 Answers

In Linux you can check /proc/<pid>/fd directory - for every open fd there will be a file, named as handle. I'm almost sure this way is non-portable.

Alternatively you can use lsof - available for Linux, AIX, FreeBSD and NetBSD, according to man lsof.

like image 111
qrdl Avatar answered Oct 10 '22 02:10

qrdl