How can I tell if a file is open elsewhere in C on

2020-02-10 06:27发布

How can I tell if a file is open in C? I think the more technical question would be how can I retrieve the number of references to a existing file and determine with that info if it is safe to open.

The idea I am implementing is a file queue. You dump some files, my code processes the files. I don't want to start processing until the producer closes the file descriptor.

Everything is being done in linux.

Thanks, Chenz

标签: c linux file-io
7条回答
男人必须洒脱
2楼-- · 2020-02-10 07:20

generally you can't do that for variuos reasons (e.g. you cannot say if the file is opened with another user).

If you can control the processes that open the file and you are try to avoid collisions by locking the file (there are many libraries on linux in order do that)

查看更多
登录 后发表回答