# Open file descriptors on a file



## jostrowski (Mar 17, 2009)

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 (Mar 19, 2009)

You could look at /usr/ports/sysutils/lsof for ideas.


----------



## fonz (Mar 19, 2009)

jostrowski said:
			
		

> 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


----------

