How to find all the file handles by a process programmatically?
Posted
by kumar
on Stack Overflow
See other posts from Stack Overflow
or by kumar
Published on 2010-03-20T04:42:19Z
Indexed on
2010/03/20
4:51 UTC
Read the original article
Hit count: 330
I have a process "x" which uses "system" C function to start ntpd daemon. I observed that ntpd are passed the open file descriptors of "x". ntpd holds on to the file descriptors even after original file is deleted. for ex: Some log files used by "x" are rotated out after sometime, but "ntpd" has file handle opened for these deleted files. Will it cause any problem?
Alternatively I thought of setting "FD_CLOEXEC" flag for all the file descriptors before calling "system" function. But as we are running as an extension library to third process "x"( "x" loads our library based on some condition), there is no easy way to know about all the file descriptors process has opened. One way is to read /proc//fd and set "FD_CLOEXEC" for each file handle and reset it back after "system" function returns. I'm using Linux 2.16. Is there any other easy way to find all the file handlers?
Thanks,
© Stack Overflow or respective owner