PDA

View Full Version : Open file descriptors on a file


jostrowski
March 17th, 2009, 17:08
Is there a userland C function available that will tell me the number of open file descriptors on a file? I'm trying to write a program that accesses a user's mailbox, and once I rename the mailbox to mailbox.lock, I want to be sure that there are no open file descriptors left open on it before I start processing the file. (I want to make sure procmail has finished any pending writes). I thought the best way to do this would be to check for remaining open file descriptors, but I cannot find a userland C function that supports this.

trev
March 19th, 2009, 02:36
You could look at /usr/ports/sysutils/lsof for ideas.

fonz
March 19th, 2009, 03:50
I thought the best way to do this would be to check for remaining open file descriptors

I don't think so. New file descriptors can be obtained between the moment you checked and the moment you started moving the file (it may be a long shot but it can happen).

Have you considered using flopen()?

Hope this helps,

Alphons