linux 串口文件锁,文件锁机制-zishang-hhg-ChinaUnix博客

这个博客内容展示了对文件锁定(F_WRLCK 和 F_RDLCK)的一系列测试,从不同区域开始并检查锁是否会成功。在某些区域,写锁和读锁会成功,而在其他区域则会因为已有锁存在而失败。测试中使用了F_GETLK来获取锁的状态。
摘要由CSDN通过智能技术生成

引用

beyes@linux-beyes:~/C> ./lock4.exe

Testing F_WRLCK on region from 0 to 5

F_WRLCK - Lock would succeed

Testing F_RDLCK on region from 0 to 5

F_RDLCK - Lock would secceed

Testing F_WRLCK on region from 5 to 10

F_WRLCK - Lock would succeed

Testing F_RDLCK on region from 5 to 10

F_RDLCK - Lock would secceed

Testing F_WRLCK on region from 10 to 15

Lock would fail. F_GETLK returned:

l_type 0, l_whence 0, l_start 10, l_len 20, l_pid 15916

Testing F_RDLCK on region from 10 to 15

F_RDLCK - Lock would secceed

Testing F_WRLCK on region from 15 to 20

Lock would fail. F_GETLK returned:

l_type 0, l_whence 0, l_start 10, l_len 20, l_pid 15916

Testing F_RDLCK on region from 15 to 20

F_RDLCK - Lock would secceed

Testing F_WRLCK on region from 20 to 25

Lock would fail. F_GETLK returned:

l_type 0, l_whence 0, l_start 10, l_len 20, l_pid 15916

Testing F_RDLCK on region from 20 to 25

F_RDLCK - Lock would secceed

Testing F_WRLCK on region from 25 to 30

Lock would fail. F_GETLK returned:

l_type 0, l_whence 0, l_start 10, l_len 20, l_pid 15916

Testing F_RDLCK on region from 25 to 30

F_RDLCK - Lock would secceed

Testing F_WRLCK on region from 30 to 35

F_WRLCK - Lock would succeed

Testing F_RDLCK on region from 30 to 35

F_RDLCK - Lock would secceed

Testing F_WRLCK on region from 35 to 40

F_WRLCK - Lock would succeed

Testing F_RDLCK on region from 35 to 40

F_RDLCK - Lock would secceed

Testing F_WRLCK on region from 40 to 45

Lock would fail. F_GETLK returned:

l_type 1, l_whence 0, l_start 40, l_len 10, l_pid 15916

Testing F_RDLCK on region from 40 to 45

Lock would fail. F_GETLK return:

l_type 1, l_whence 0, l_start 40, l_len 10, l_pid 15916

Testing F_WRLCK on region from 45 to 50

Lock would fail. F_GETLK returned:

l_type 1, l_whence 0, l_start 40, l_len 10, l_pid 15916

Testing F_RDLCK on region from 45 to 50

Lock would fail. F_GETLK return:

l_type 1, l_whence 0, l_start 40, l_len 10, l_pid 15916

Testing F_WRLCK on region from 50 to 55

F_WRLCK - Lock would succeed

Testing F_RDLCK on region from 50 to 55

F_RDLCK - Lock would secceed

Testing F_WRLCK on region from 55 to 60

F_WRLCK - Lock would succeed

Testing F_RDLCK on region from 55 to 60

F_RDLCK - Lock would secceed

Testing F_WRLCK on region from 60 to 65

F_WRLCK - Lock would succeed

Testing F_RDLCK on region from 60 to 65

F_RDLCK - Lock would secceed

Testing F_WRLCK on region from 65 to 70

F_WRLCK - Lock would succeed

Testing F_RDLCK on region from 65 to 70

F_RDLCK - Lock would secceed

Testing F_WRLCK on region from 70 to 75

F_WRLCK - Lock would succeed

Testing F_RDLCK on region from 70 to 75

F_RDLCK - Lock would secceed

Testing F_WRLCK on region from 75 to 80

F_WRLCK - Lock would succeed

Testing F_RDLCK on region from 75 to 80

F_RDLCK - Lock would secceed

Testing F_WRLCK on region from 80 to 85

F_WRLCK - Lock would succeed

Testing F_RDLCK on region from 80 to 85

F_RDLCK - Lock would secceed

Testing F_WRLCK on region from 85 to 90

F_WRLCK - Lock would succeed

Testing F_RDLCK on region from 85 to 90

F_RDLCK - Lock would secceed

Testing F_WRLCK on region from 90 to 95

F_WRLCK - Lock would succeed

Testing F_RDLCK on region from 90 to 95

F_RDLCK - Lock would secceed

Testing F_WRLCK on region from 95 to 100

F_WRLCK - Lock would succeed

Testing F_RDLCK on region from 95 to 100

F_RDLCK - Lock would secceed

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值