I created a fifo pipe
$ mkfifo pipename
Now if I write somthing into it, the command won’t not return,
$ echo "foo" > pipename
until I read it:
$ cat < pipename
foo
Also, also read command won’t return until something is written to it.
Now, I would like to create a such a thing (actually, maybe this thing should not be considered to be a pipe, rather some sort of buffer) that
- reading command will return immediately, regardless of there is something in the pipe or not (if pipe is empty, then reading should return immediately with zero bytes)
- write command returns immediately
Thanks
Use a fifo, but write your own reader and writer. Open the fifo with O_NONBLOCK set, and open will return immediately if no other process has the other side open. Your write command will return immediately (as requested), but the data will be lost. If you want the data to persist, use a regular file.