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?
In Linux you can check /proc/<pid>/fd directory - for every open fd there will be a file, named as handle.
You can use /proc file system or the lsof command to find all the file descriptors used 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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With