In Linux, is it possible to get the reference count value (counter value of using a file) for a specified file by descriptor by using non-kernel API?
© 2022 - 2024 — McMap. All rights reserved.
In Linux, is it possible to get the reference count value (counter value of using a file) for a specified file by descriptor by using non-kernel API?
© 2022 - 2024 — McMap. All rights reserved.
lstat(fd, &buf)
and checkbuf.st_nlink
. If you mean number of open descriptors, you can usefcntl(fd, F_SETLEASE, F_RDLCK)
(iffd
opened read-only) orfcntl(fd, F_SETLEASE, F_WRLCK)
to place a lease on the file to check if the file is open for writing (F_RDLCK
) or at all (F_WRLCK
) -- failing in those cases --, and getting a signal (plus a grace lease-break-time to release the lease) if such open occurs while the lease is held. However, this is not a counter, is very Linux-specific, and is quite limited otherwise too; seeman 2 fcntl
for details. – Obverse