Deletion of open named pipes

I am creating and opening a named pipe (using mkfifo() ) and the open is blocked (till someone else opens in write mode). However, another process is easily able to delete the pipe file while the first process is blocked on it. Is this behaviour ok? Shouldn't the file be locked because someone else is blocked on it?

 

if you want to "lock" the file, you can put it in a directory with no write permissions, thereby disabling the ability to delete it.

One of the basic ideas in UNIX is that an open file can be moved or deleted at will. The file/device/FIFO itself will continue to exist, without a name, until it is closed by the last process which has a descriptor on it.

Coming from a Windows background people are used to thinking that a file which is "in use" is somehow protected from certain kinds of operations. Not true on UNIX.

Please note that the named pipe was created with permissions 0400. This means only the owner would have the right to modify/delete it, right

No. Any user can delete any file, providedthey have write permissions on the directory that file is in. It has nothing to do with who owns the file, or the permissions on the file itself.

So, to prevent deletion of the FIFO, make a directory, put the FIFO in this directory, then remove write permissions on the directory.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值