Deutsch English Français Italiano |
<vqo4og$1l4ia$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Lawrence D'Oliveiro <ldo@nz.invalid> Newsgroups: comp.os.linux.misc Subject: O_RDWR On Named Pipes Date: Tue, 11 Mar 2025 01:48:01 -0000 (UTC) Organization: A noiseless patient Spider Lines: 22 Message-ID: <vqo4og$1l4ia$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Tue, 11 Mar 2025 02:48:01 +0100 (CET) Injection-Info: dont-email.me; posting-host="fb3f8814a23c1b5929be502852c6d2d1"; logging-data="1741386"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19WILazZ+p3KVj/t6QuR6BI" User-Agent: Pan/0.162 (Pokrosvk) Cancel-Lock: sha1:+hM7TFdqHeDQspxIYuYyOW36toA= Typically when you open a file descriptor on a pipe, it’s either for reading or writing, but not both. However, when you open a named pipe, it is possible to specify the mode O_RDWR; but does this work, or return an error? And if it doesn’t return an error, what exactly does it do? I checked some relevant man pages <https://manpages.debian.org/fifo(7)> <https://manpages.debian.org/pipe(7)>, but they completely avoid any mention of O_RDWR mode. So I tried it. And it works without error. You get back a single file descriptor, that you can use for both writing to the pipe and reading from it. So if no other processes open the same named pipe, you can write something to it (I suppose until the kernel buffer fills up), and read the same thing back again. Not very useful, on the face of it. But I guess it means you can (with appropriate coordination from both ends) switch the direction of data flow at any point, without having to close and reopen the named pipe. Basically O_RDWR gives you a half-duplex communication channel, where O_RDONLY and O_WRONLY will give you the ends of a simplex (unidirectional) channel.