Open file descriptors on a file

jostrowski

New Member


Messages: 11

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

Aspiring Daemon

Reaction score: 141
Messages: 750

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

fonz

Son of Beastie

Reaction score: 369
Messages: 2,560

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
 
Top