开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜