Getting a file descriptor from a filename in a POSIX system - or how to close a file having only the filename
Could you please help me with an opposite issue? I need to close a file, but I am only given a filename (I presume I need to convert it to a file descriptor). Is it开发者_运维百科 possible at all, and if so - in which way? Thanks.
Using POSIX standard APIs? No.
On some linux systems, you might be able to figure it out via /proc/PID/fd.
You can't close a file for another process. If it's in your process, you should keep either a filehandle or a file descriptor around; or you might use /proc/self/fd
as bmargulies suggested.
精彩评论