Linux: defining a file descriptor identifier via procfs

I am trying to determine if it is possible to distinguish two separate handles in one file and one descriptor with two file descriptors pointing to it using metadata from procfs.

Case 1: Two File Descriptors

# setup
exec 3>test.lck
exec 4>test.lck
# usage
flock -x 3  # this grabs an exclusive lock
flock -s 4  # this blocks
echo "This code is never reached"

Case 2: one pen, two FD

# setup
exec 3>test.lck
exec 4>&3
# usage
flock -x 3  # this grabs an exclusive lock
flock -s 4  # this converts that lock to a shared lock
echo "This code gets run"

If I check the state of the system from the user environment after completing the “setup” phase and before “using”, and I want to distinguish between the two cases, are the necessary metadata available? If not, what is the best way to expose him? (Is adding kernelspace pointers in a /proc/*/fdinfosensible action that apparently can take as a patch?)

+4
1

proc, . , script.

, , , , .

, Linux- , . , , , , . , . , , .

+1

Source: https://habr.com/ru/post/1629713/


All Articles