Deletion of open named pipes

来源:互联网 发布:淘宝评价怎么p图 编辑:程序博客网 时间:2024/05/19 07:24

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.

原创粉丝点击